我jsp更新数据的出错! 你只是测试了你的executeQuery()方法,而你jsp中用的是executeUpdate()方法你仔细测测可能会发现原因 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我就是要运行executeUpdate()这个方法拉,我逻辑上是没有错拉,不行就是这个方法executeUpdate()我只是说明点executeQuery()我这个方法是没有错的。 update好像必须有返回值的你的update执行语句这样写一下:sql=" update tb_user set name='xishui' where name='xishuichi'";int col=stmt.executeUpdate(sql); 不好意思 拉写了1句Statement stmt=conn.createStatement();sql=" update tb_user set name='xishui' where name='xishuichi'";int col=stmt.executeUpdate(sql); 不可以拉!!! warehouseleet(堆栈.net)我的conn是bean引进来的。。 不是 你理解错了,我的意思不是你用什么方式连接的库,而是要UPDATE的话,它一定要有返回值的,而且是 int形的!!明白了么??? 你的不可以 warehouseleet(堆栈.net) 你定义记录集对象了么?Statement pstmt=conn.createStatement(); 你把stmt.executeUpdate(sql);换一下,使用stmt.execute(sql);试一下看看! 你应该生成statement变量,调用executeUpdate() 我用了,statement stmt=executeUpdate(sql); 还是出这样的错误 org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:372) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236) javax.servlet.http.HttpServlet.service(HttpServlet.java:802)那大侠真的要帮帮小弟我都帖出两天了,还没解决问题啊 .拜托!!1 public void executeUpdate(String sql) throws Exception试下把throws Exception删除,看有没有抛出错误你这样写statement stmt=executeUpdate(sql); 肯定是错的Statement stmt=conn.createStatement();sql=" update tb_user set name='xishui' where name='xishuichi'";stmt.executeUpdate(sql); 你的程序我试了一下,如果把你bean 里的方法executeQuery()中stm.executeQuery(sql)一句,该成int t=stm.executeQuery(sql),在我机器上是可以使用的。jsp*******************************<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title>无标题文档</title></head><body><jsp:useBean id="conn" scope="page" class="opendb.opendb"/><% String sql; try{ sql=" update message set name='b' where name='a'"; conn.executeUpdate(sql); } catch(Exception e) { System.out.println(e.getMessage()); } %></body></html>bean******************************package opendb;import java.sql.*;public class opendb{ String sdbdirver="com.microsoft.jdbc.sqlserver.SQLServerDriver"; String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=newdate"; String user="sa"; String password="sa"; Connection conn=null; ResultSet rs=null; public opendb() { try{ Class.forName(sdbdirver); } catch(java.lang.ClassNotFoundException e){ System.err.println("opendb():"+e.getMessage()); } } public ResultSet executeQuery(String sql) throws Exception { try{ sql= new String(sql.getBytes("GBK"),"ISO8859_1"); conn=DriverManager.getConnection(url,user,password); Statement stmt=conn.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_READ_ONLY); rs=stmt.executeQuery(sql); } catch(SQLException ex) { System.out.println("executeQuery(sql)"+ex.getMessage()); } return rs; } public void executeUpdate(String sql) throws Exception { sql= new String(sql.getBytes("GBK"),"ISO8859_1"); try{ conn=DriverManager.getConnection(url,user,password); Statement stmt=conn.createStatement(); int t=stmt.executeUpdate(sql); } catch(SQLException ex){ System.out.println("executeUpdate(sql)"+ex.getMessage()); } } } iframe 问题 用过UEditor的给看看 一个查询的需求问题,希望各位给我提供解决思路! web工程找不到资源文件的问题 请教一个问题 一道面试题:jsp中,如何获得服务器中session的总数 求助::jscookMenu用到Tiles框架中失效,帮忙看看为什么? 一个JS文件,直接调用它的绝对地址没问题,下载下来调用就出现错位 关于JS方面的问题,请问高手们帮帮忙哦!源代码发出来了 javaScript取值的问题???????????? #############连SQL Server2000库时抛出奇怪的错误################ 在线等:关于结果集关闭的问题
不行就是这个方法executeUpdate()我只是说明点executeQuery()我这个方法是没有错的。
sql=" update tb_user set name='xishui' where name='xishuichi'";int col=stmt.executeUpdate(sql);
我的conn是bean引进来的。。
试一下看看!
还是出这样的错误
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:372)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
那大侠真的要帮帮小弟我都帖出两天了,还没解决问题啊 .拜托!!1
试下把throws Exception删除,看有没有抛出错误
你这样写statement stmt=executeUpdate(sql); 肯定是错的
Statement stmt=conn.createStatement();
sql=" update tb_user set name='xishui' where name='xishuichi'";
stmt.executeUpdate(sql);
jsp*******************************
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<body>
<jsp:useBean id="conn" scope="page" class="opendb.opendb"/><%
String sql;
try{
sql=" update message set name='b' where name='a'";
conn.executeUpdate(sql);
}
catch(Exception e)
{
System.out.println(e.getMessage());
} %></body>
</html>
bean******************************
package opendb;
import java.sql.*;
public class opendb
{
String sdbdirver="com.microsoft.jdbc.sqlserver.SQLServerDriver";
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=newdate";
String user="sa";
String password="sa";
Connection conn=null;
ResultSet rs=null;
public opendb()
{
try{
Class.forName(sdbdirver);
}
catch(java.lang.ClassNotFoundException e){
System.err.println("opendb():"+e.getMessage());
}
}
public ResultSet executeQuery(String sql) throws Exception
{
try{
sql= new String(sql.getBytes("GBK"),"ISO8859_1");
conn=DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_READ_ONLY);
rs=stmt.executeQuery(sql);
}
catch(SQLException ex)
{
System.out.println("executeQuery(sql)"+ex.getMessage());
}
return rs;
}
public void executeUpdate(String sql) throws Exception
{
sql= new String(sql.getBytes("GBK"),"ISO8859_1");
try{
conn=DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement();
int t=stmt.executeUpdate(sql);
}
catch(SQLException ex){
System.out.println("executeUpdate(sql)"+ex.getMessage()); }
}
}