我的代码是:
if(searchby.equals("City"))
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("\n Driver loaded");
Connection con=DriverManager.getConnection("jdbc:odbc:wanisamajDB");
Statement stmt=con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT Name FROM FAMILYcensus WHERE Name.City LIKE='" + tfsearch.getText() + "'");
System.out.println("Hi");
rs.next();
String city = rs.getString("NAME");
System.out.println("NAME: " + city );
JOptionPane.showMessageDialog(null, "RECORD FOUND");
tasearch.setText(city);
}
catch (Exception e)
{
System.out.println("EXCEPTION " + e);
}
}
答案 0 :(得分:5)
在sql中没有like = 'boston'
这样的运算符。
它可以是city = 'boston'
或city like 'boston'
,其中第二个可以容忍差异,具体取决于数据库的配置方式。