Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 1 of 1

Thread: Help!

  1. #1
    Junior Member
    Join Date
    Mar 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help!

    Hi frnds i m new to the forum.
    I have a code through which i m trying to check whether the combobox item selected exist in my database or not.

    But the problem is when i pass the getSelectedItem method in sql query, database does not understand that and neither it gives me an error.
    Please Help!!!

    Here goes my code.

    /* Here the code is on button click event*/

    else if(text1.getText().equals("TYCS"))
    {
    try
    {
    connn=DriverManager.getConnection("jdbcdbc:Attendance");
    st=connn.createStatement();
    rset=st.executeQuery("select"+" "+text2.getText()+" "+"from TYCS_Sub where mon="+" ' "+Mnt.getSelectedItem()+ " ' ");

    /* wat i m trying to check is the item selected in combo box by user exist or not*/

    System.out.println("In Tycs");

    while(rset.next())
    {
    bmw=rset.getInt(1); // 'bmw' & 'hon' are variables whose data type is int

    hon=Integer.parseInt(text2.getText());

    System.out.println("hon is:"+hon);

    if(bmw==hon)
    {
    JOptionPane.showMessageDialog(Attendance.this,"Dat a exist for this Month!","Message",JOptionPane.ERROR_MESSAGE);
    break;
    }
    }
    System.out.println("bmw is:"+bmw);
    }
    catch(SQLException esq)
    {
    System.out.println("check "+esq);
    }

    Also, instead of using getSelectedItem method i tried using direct month(my combo box is to select a month) value like 'june', 'july' etc... the query executes perfectly. Also it checks the database and show dialog box that data for the month exists. But wen it comes to using the method it does not work.
    Last edited by Amit20; March 12th, 2011 at 03:08 PM.