跟据弹出的对话框输入姓名,以此为查询数据库中满足要求的记录,代码:try{
String inputValue ;
inputValue = JOptionPane.showInputDialog("请输入要查询的姓名!");
while(rs.next()){ //rs也为一个数据集 rs=stmt.executeQuery("SELECT Name,ID,Sex,Score FROM student"); if(inputValue.equals(rs.getString("Name")))
i++;
}
if(i<=0)
JOptionPane.showMessageDialog(null, "查无此记录!", "Error", JOptionPane.WARNING_MESSAGE);
else{
rs1=stmt.executeQuery("SELECT * FROM student WHERE Name='"+inputValue+"'");
rs1.next();
score.setText(rs1.getString("Score"));
name.setText((rs1.getString("Name")));
id.setText(rs1.getString("ID"));
if(rs1.getString("Sex").equals("男"))
sex.setSelectedCheckbox(m);
else
sex.setSelectedCheckbox(w);
}
}
catch(Exception e5){
e5.printStackTrace();
}结果老是报这样的错:java.sql.SQLException: [Microsoft][ODBC 驱动程序管理器] 无效的游标状态
急求解啊!!!!!
String inputValue ;
inputValue = JOptionPane.showInputDialog("请输入要查询的姓名!");
while(rs.next()){ //rs也为一个数据集 rs=stmt.executeQuery("SELECT Name,ID,Sex,Score FROM student"); if(inputValue.equals(rs.getString("Name")))
i++;
}
if(i<=0)
JOptionPane.showMessageDialog(null, "查无此记录!", "Error", JOptionPane.WARNING_MESSAGE);
else{
rs1=stmt.executeQuery("SELECT * FROM student WHERE Name='"+inputValue+"'");
rs1.next();
score.setText(rs1.getString("Score"));
name.setText((rs1.getString("Name")));
id.setText(rs1.getString("ID"));
if(rs1.getString("Sex").equals("男"))
sex.setSelectedCheckbox(m);
else
sex.setSelectedCheckbox(w);
}
}
catch(Exception e5){
e5.printStackTrace();
}结果老是报这样的错:java.sql.SQLException: [Microsoft][ODBC 驱动程序管理器] 无效的游标状态
急求解啊!!!!!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货