![](https://iknow-base.cdn.bcebos.com/lxb/notice.png)
jsp数据库取出数据再存入到另一个表中
Class.forName("com.mysql.jdbc.Driver");Connectioncon=DriverManager.getConnection("jdb...
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/library","root","zhoujie");
Statement sta=con.createStatement();
String sql="select * from bookinfo where bookid='"+bookno1+"'";
ResultSet res=sta.executeQuery(sql);
while(res.next()){
String bookid=res.getString(1);
String bookname=res.getString(2);
String price=res.getString(3);
String booktime=res.getString(4);
Class.forName("com.mysql.jdbc.Driver");
Connection con1=DriverManager.getConnection("jdbc:mysql://localhost:3306/library","root","zhoujie");
Statement sta1=con1.createStatement();
String sqlq="insert into delbookmes"+
"(bookid,bookname,price,in_time,time)"+
" values('"+bookid+"','"+bookname+"','"+price+"','"+booktime+"','"+time+"')";
ResultSet coun=sta.executeQuery(sqlq);
哪错了???? 展开
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/library","root","zhoujie");
Statement sta=con.createStatement();
String sql="select * from bookinfo where bookid='"+bookno1+"'";
ResultSet res=sta.executeQuery(sql);
while(res.next()){
String bookid=res.getString(1);
String bookname=res.getString(2);
String price=res.getString(3);
String booktime=res.getString(4);
Class.forName("com.mysql.jdbc.Driver");
Connection con1=DriverManager.getConnection("jdbc:mysql://localhost:3306/library","root","zhoujie");
Statement sta1=con1.createStatement();
String sqlq="insert into delbookmes"+
"(bookid,bookname,price,in_time,time)"+
" values('"+bookid+"','"+bookname+"','"+price+"','"+booktime+"','"+time+"')";
ResultSet coun=sta.executeQuery(sqlq);
哪错了???? 展开
2个回答
展开全部
代码是连在一起的么?建议你把变量定义成全局的,不要放在while循环里面,如下:
String bookid = “”;
while(res.next()){
bookid=res.getString(1);
}
而且Connection 第一次已经取了,也可以这样定义了之后直接在下面进行使用,没必要再写一遍
String bookid = “”;
while(res.next()){
bookid=res.getString(1);
}
而且Connection 第一次已经取了,也可以这样定义了之后直接在下面进行使用,没必要再写一遍
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询