MySQL的數據我要檢查新輸入的數據是否已經在表中比較整數文本字段值在Java
代碼:
txtNo = new JTextField();
{
try {
Class.forName("com.mysql.jdbc.Driver");
String srcurl1 = "jdbc:mysql://localhost:3306/DB_name";
Connection con = DriverManager.getConnection(srcurl1,"root","paswrd");
Statement stmt1 = con.createStatement();
ResultSet rs1 = stmt1.executeQuery("select No from bank where No='"+txtNo.getText()+"' ");
int ch =rs1.getInt("No");
int ch4= Integer.parseInt(txtNo.getText());
if(ch==ch4) // input 58 == 58
System.out.println("already exits");
}
catch(Exception e)
{
System.out.println("Exception:"+e);
}
}
錯誤: Exception:java.sql.SQLException: Illegal operation on empty result set.
什麼是在您的數據庫中的列*沒有*的SQL類型?它被聲明爲一個整數或一個varchar? – Sujay
NO被聲明爲varchar –