importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.ResultSet;importjava.sql.Statement;publicclassdb{publicstaticvoidmain(String[]args){StringdbUrl="jdb...
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class db {
public static void main(String[] args) {
String dbUrl ="jdbc:odbc:test";
String dbUser = "";
String dbPwd = "";
Connection conn = null;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
conn = DriverManager.getConnection(dbUrl, dbUser, dbPwd);
Statement st=conn.createStatement();
String sql="select * from t1 ";
ResultSet rs=st.executeQuery(sql);
String name=null;
String xy;
String number;
while(rs.next()){
name=rs.getString(1);
xy=rs.getString(2);
number=rs.getString(3);
String sqll="update t2 set number='" + number + "' where name='" + name + "' and xy='" + xy + "'";
st.executeUpdate(sqll);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
我在while语句里面也用了sql语句进行操作,这样是不是错的啊?我看反悔了错误提示
java.sql.SQLException: ResultSet is closed
at sun.jdbc.odbc.JdbcOdbcResultSet.checkOpen(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcResultSet.next(Unknown Source)
at db.main(db.java:23)
提示错误是ResultSet is closed数据库连接绝对没有问题
加了这两句之后就出错了
String sqll="update t2 set number='" + number + "' where name='" + name + "' and xy='" + xy + "'";
st.executeUpdate(sqll);
展开