com.microsoft.sqlserver.jdbc.SQLServerException: 结果集没有当前行。
代码如下:publicvoidsave(){try{getConnection();Connectionconn;conn=java.sql.DriverManager....
代码如下:
public void save() {
try{
getConnection();
Connection conn;
conn=java.sql.DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DatabaseName=JIN", "sa","123");
Statement st=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
String inputno1=text1.getText();
String drugno1=text2.getText();
String inputam1=text3.getText();
String inputti1=text4.getText();
String supplier1=text5.getText();
String inputp1=text6.getText();
String inputc1=text7.getText();
if(inputno1.equals("")){
JOptionPane.showMessageDialog(null,"进货单号不能为空!");
}
else{
String sql1= "insert into jin values("+inputno1+","+drugno1+","+inputam1+",'"+inputti1+"','"+supplier1+"','"+inputp1+"','"+inputc1+"')";
st.executeUpdate(sql1);
int i,j;
ResultSet rs;
i=Integer.parseInt(inputam1); //string类转换为int类型
String sql2="select 药品库存 from info where 药品编号="+inputno1+"";
rs=st.executeQuery(sql2);
rs.next();
j=rs.getInt("药品库存");
j=i+j;
String sql3="update info set 药品库存="+j+" where 药品编号="+inputno1+"";
st.executeUpdate(sql3);
JOptionPane.showMessageDialog(null,"登记成功!");
}
}catch(Exception e) {
JOptionPane.showMessageDialog(null,"失败");
e.printStackTrace();
}
}
是在虚拟机xp上做的,java工具是eclipse,数据库是sql server 2000
而且,我之前使用是正确的,但是过一会再试就报错了。。。然后我胡乱的把rs.next()改成了rs.first(),又正确了,结果我改了另一个部件回来再试,又报错了OTZ
麻烦各位帮我看看吧 展开
public void save() {
try{
getConnection();
Connection conn;
conn=java.sql.DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DatabaseName=JIN", "sa","123");
Statement st=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
String inputno1=text1.getText();
String drugno1=text2.getText();
String inputam1=text3.getText();
String inputti1=text4.getText();
String supplier1=text5.getText();
String inputp1=text6.getText();
String inputc1=text7.getText();
if(inputno1.equals("")){
JOptionPane.showMessageDialog(null,"进货单号不能为空!");
}
else{
String sql1= "insert into jin values("+inputno1+","+drugno1+","+inputam1+",'"+inputti1+"','"+supplier1+"','"+inputp1+"','"+inputc1+"')";
st.executeUpdate(sql1);
int i,j;
ResultSet rs;
i=Integer.parseInt(inputam1); //string类转换为int类型
String sql2="select 药品库存 from info where 药品编号="+inputno1+"";
rs=st.executeQuery(sql2);
rs.next();
j=rs.getInt("药品库存");
j=i+j;
String sql3="update info set 药品库存="+j+" where 药品编号="+inputno1+"";
st.executeUpdate(sql3);
JOptionPane.showMessageDialog(null,"登记成功!");
}
}catch(Exception e) {
JOptionPane.showMessageDialog(null,"失败");
e.printStackTrace();
}
}
是在虚拟机xp上做的,java工具是eclipse,数据库是sql server 2000
而且,我之前使用是正确的,但是过一会再试就报错了。。。然后我胡乱的把rs.next()改成了rs.first(),又正确了,结果我改了另一个部件回来再试,又报错了OTZ
麻烦各位帮我看看吧 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |