-
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("jdbc:odbc:Atten dance");
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.