我使用此代码简单显示任意随机选择的ID的数据,但发生此错误我看到有关此错误的各种帖子,但我没有为我的程序提供任何结果,请告诉我什么是问题。 我正在使用以下代码
public class Demo {
public static void main(String[] args) throws Exception {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:StudentInfo_Oracle","System","Aadi@123");
Scanner s = new Scanner(System.in);
String disq = "Select * from Sample where Id = ?";
System.out.println("Enter id number which data want to display: ");
int id = s.nextInt();
PreparedStatement dis = con.prepareStatement(disq);
dis.execute();
ResultSet rs = dis.getResultSet();
while (rs.next()) {
System.out.println(rs.getInt(1));
System.out.println(rs.getString(2));
}
}
}
答案 0 :(得分:0)
在PreparedStatement设置值?
PreparedStatement dis = con.prepareStatement(disq);
dis.setInt(1,id);