站内搜索: 请输入搜索关键词

当前页面: 开发资料首页JSP 专题MySQL在JSP环境下的操作应用

MySQL在JSP环境下的操作应用

摘要: MySQL在JSP环境下的操作应用


前提:

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

</td> </tr> <tr> <td vAlign=top align=left height="100%">
↑返回目录
前一篇: 动态网页编程:JSP入门学习教程
后一篇: Eclipse Forms设计漂亮UI之简介