前提: 将MySQL数据库的驱动放在工作目录的web-inf\lib目录下(这样才能在JSP中连结上) 用JavaBean连接,将编译好得.class文件放在classes文件下,若文件包含package指令,则要放到 指定的目录下。 此时,数据查询没问题,但是update,delete和insert都无效。(在SQL Server 中可行) 问题解决,察看JDK说明,找到Statement的方法段ResultSet executeQuery(String), int executeUpdate(String) 修改JavaBean,添加executeUpdate方法,修改.jsp文件,将非select时指向executeUpdate,测试update,insert, delete都成功实现 executeQuery方法代码: public ResultSet executeQuery(String sqlString) { rs=null; try { conn=DriverManager.getConnection(connURL,userName,pwd); Statement stmt=conn.createStatement(); rs=stmt.executeQuery(sqlString); } catch(SQLException ex) { System.err.println("aq.executeQuery:"+ex.getMessage()); } return rs; } excuteUpdate方法代码: public int executeUpdate(String sqlString) { instructionCount=0; try { conn=DriverManager.getConnection(connURL,userName,pwd); Statement stmt=conn.createStatement(); stmt.executeUpdate(sqlString); instructionCount=1; } catch(SQLException ex) { System.err.println("aq.executeQuery:"+ex.getMessage()); } return instructionCount; } 新问题:在MySQL使用utf-8来支持全中文时,再次对支付串进行编解码会破坏中文的输入, 在插入和更新数据时,取消原来用GBK的new String 来编码 |
|小黑屋|最新主题|手机版|微赢网络技术论坛 ( 苏ICP备08020429号 )
GMT+8, 2024-9-30 11:26 , Processed in 0.088152 second(s), 12 queries , Gzip On, MemCache On.
Powered by Discuz! X3.5
© 2001-2023 Discuz! Team.