我正在编写一个代码,用于输入文本字段中的数字(密码),搜索天气数字是否存在于数据库中,如果存在其他页面的红色,则显示错误的密码。请帮助我,因为我是一个新手,我被卡住了。 我使用jsp连接到oracle数据库和html作为UI。
Class.forName("Oracle.jdbc.OracleDriver");
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","scott","wipro123");
String q = "Select * from Login where pin="pin_textbox"";
rs=st.executeQuery(q);
System.out.println("catty");
while(rs.next())
{
// dont know what to write after this... Please help me.
}
答案 0 :(得分:1)
参考here
int numberOfRows = null;
String q = "Select count(*) from Login where pin=?";
PreparedStatement pst = con.prepareStatement(q);
pst.setString(1, pin_textbox);
ResultSet rs = pst.executeQuery();
if (rs.next()) {
numberOfRows = rs.getInt(1);
} else {
System.out.println("error: could not get the record counts");
}
通过使用numberOfRows >= 1
条件,您可以重定向或显示错误页面