I'm not able to execute the query here.It says the above mentioned error.I have tried with 'Select * from customer' query and it is working.I can't figure out where am i going wrong.Please help and thanks in advance.
The full query is- SELECT CUSTOMER_ID,FIRST_NAME,LAST_NAME,COUNTRY,AGE,GENDER,EMAIL_ADDRESS FROM CUSTOMER WHERE FIRST_NAME='SHIVAM';
The error message is- com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErr orException: Unknown coloumn 'SHIVAM' in 'where clause'
DefaultTableModel model;
model=(DefaultTableModel)tblSearchCustomer.getModel();
try{
Class.forName("java.sql.Driver");
Connection con= DriverManager.getConnection("jdbc:mysql://localhost:3306/divign","root","password");
Statement stmt=con.createStatement();
String sfld=(String) searchfldCB.getSelectedItem();
//this stands for Search Field(ComboBox)
String op=(String) opCB.getSelectedItem();
//this stands for operator(ComboBox)
String crit=criteriaTF.getText();
//this stands for criteria
String query="SELECT CUSTOMER_ID,FIRST_NAME,LAST_NAME,COUNTRY,AGE,GENDER,EMAIL_ADDRESS FROM CUSTOMER WHERE" + sfld+""+op+""+crit+" ;";
//This Query is not Executing
ResultSet rs=stmt.executeQuery(query);
while(rs.next()) {
model.addRow (new Object[ ] {
rs.getInt(1),rs.getString(2),rs.getString(3),rs.getString(4),rs.getInt(5),
rs.getString(6),rs.getInt(7)
} );
}
rs.close();
stmt.close();
con.close();
}
catch(Exception e){
JOptionPane.showMessageDialog(null,e.toString());
}
WHERE" + sfld+""+op+""+crit+" ;