问题描述
<%Stringusername=(String)session.getAttribute("username");Class.forName("com.mysql.jdbc.Driver").newInstance();//DriverManager.registerDriver(newcom.mysql.jdbc.Driver());StringdbUrl="jdbc:mysql://localhost:3306/bookdb?user=root&password=1234&useUnicode=true&characterEncoding=GB2312";Connectioncon=java.sql.DriverManager.getConnection(dbUrl);Statementstmt=con.createStatement();Stringsql="SELECT*fromshopping_cartWHEREbuyer_name='"+username+"'";ResultSetrst=stmt.executeQuery(sql);while(rst.next()){Stringbookname=rst.getString("bookname");Stringbuyer_name=username;Stringseller_name=rst.getString("username");Stringprice=rst.getString("price");StringsqlInsert="INSERTINTOdeal(book_name,buyer_name,seller_name,price)VALUES('"+bookname+"','"+buyer_name+"','"+seller_name+"','"+price+"')";System.out.println(sqlInsert);stmt.executeUpdate(sqlInsert);}out.println("<tr><td>购买成功!</tr></td>");stmt.close();con.close();%>运行的时候总是要报错,网上说要用Statementstmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);我试了还是不行,请大神帮我看下
解决方案
解决方案二:
你查下api,看看statement的构造函数的那些参数都是干什么用的,然后就可以根据需求初始化statement了