MySQL在JSP环境下的操作应用

王朝mysql·作者佚名  2006-11-24
窄屏简体版  字體: |||超大  

前提:

将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 来编码

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航