我有一個名爲'customer'的mysql表。 serialnumber(int),name(varchar),gender(varchar)是表字段。從數據庫中獲取值
我有一個int變量α= 2
我想當SERIALNUMBER從表獲取值=一個。那就是當serialnumber = 2時它應該顯示特定客戶的名字。
String url="jdbc:mysql://localhost/shopping";
String usr ="root";
String pass = "rootpassword";
session.setAttribute("URL", url);
session.setAttribute("user", usr);
session.setAttribute("passwd", pass);
String connectionURL = (String)session.getAttribute("URL");
String user = (String)session.getAttribute("user");
String passwd = (String)session.getAttribute("passwd");
Connection connection = null;
Statement statement = null;
ResultSet rs = null;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
connection = DriverManager.getConnection(connectionURL, user, passwd);
statement = connection.createStatement();
rs=statement.executeQuery("select * from customer where serialnumber like '%a%' ");
while (rs.next()) {
out.println("Customer Name: ");
out.println(rs.getString("name"));
}rs.close();
}catch(Exception ce){out.println(ce);}
這不會拋出任何東西。但是當我給rs.execute查詢中的數字時,它顯示客戶名稱。如何解決這個問題,我的錯誤是什麼?
感謝
爲什麼當你想測試平等時使用'LIKE'? –