你不需要在你的类里写execUpdate()这个方法了。
我感觉
<jsp:useBean id="connDB" scope="page" class="myConnection.connDB"/>
<%
connDB.executeQuery("update userinfo set addr='"+addr+"' where id="+userID);
%>
就可以实现数据的更新了
我感觉
<jsp:useBean id="connDB" scope="page" class="myConnection.connDB"/>
<%
connDB.executeQuery("update userinfo set addr='"+addr+"' where id="+userID);
%>
就可以实现数据的更新了
解决方案 »
- 在struts.xml的result配置中使用OGNL表达式,报错Invalid result location value/parameter,求解决办法!
- 关于jsp下拉菜单异常如何处理。求教!
- 写junit的时候MYSQL中文显示乱码
- FCKeditor2.6用在jsp里,上传图片出错!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- oralce数据库中相除取值问题
- 项目发布到服务器上的问题,本地测试功过。
- ■■新手请教一个问题:JSP可以使用JAVA的所有功能吗?
- Jsp、servlet、javabean成熟商用系统源码(有在线演示)
- smartupload的问题:输入中文为什么存到数据库当中是乱码?--------十万火急,丢工作了!!
- 帮帮忙!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! :(
- 测试服务器并发连接数的问题
- servlet怎样以共享方式连接数据库?
//String s=str;
try{
stmt=conn.createStatement();
stmt.executeUpdate(sql);
}
catch(SQLException ex){
}
}
//
public int execUpdate(String sql){
int result=0;
try{
stmt=conn.createStatement();
stmt.executeUpdate(sql);
}
catch(SQLException ex){
}
return result;//更新或者修改的记录树
}
type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception javax.servlet.ServletException: myConnection.connDB.execUpdate(Ljava/lang/String;)I
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:867)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:800)
org.apache.jsp.testSql_jsp._jspService(testSql_jsp.java:113)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
root cause java.lang.NoSuchMethodError: myConnection.connDB.execUpdate(Ljava/lang/String;)I
org.apache.jsp.testSql_jsp._jspService(testSql_jsp.java:92)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
note The full stack trace of the root cause is available in the Tomcat logs.
而你的("update userinfo set addr='"+addr+"' where id="+userID);引号没有加对是不是啊。后面少引号。看看是不是应该这样。("update userinfo set addr='"+addr+"' where id='"+userID+"'");
我说对的话给我点分哦,我想要分啊
"update userinfo set addr='"+addr+"' where id='"+userID+"'"
吗?
import java.sql.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;public class SqlAction
{ Context ctx;
DataSource ds;
Connection conn;
Statement stmt;
ResultSet rs;
CallableStatement cstmt; public SqlAction()
{
ctx = null;
ds = null;
conn = null;
stmt = null;
rs = null;
cstmt = null;
try
{
ctx = new InitialContext();
ds = (DataSource)ctx.lookup("MySource");
}
catch(Exception e)
{
System.err.println("SqlAction:".concat(e.getMessage()));
}
} public CallableStatement GetCstmt(String proc)
{
try
{
conn = ds.getConnection();
cstmt = conn.prepareCall(proc);
}
catch(SQLException ex)
{
System.err.println("SqlAction.ExecInsert:".concat(String.valueOf(String.valueOf(ex.getMessage()))));
}
return cstmt;
} public void ExecInsert(String sql)
{
try
{
conn = ds.getConnection();
stmt = conn.createStatement();
stmt.executeUpdate(sql);
closeStmt();
closeConn();
}
catch(SQLException ex)
{
System.err.println("SqlAction.ExecInsert:".concat(String.valueOf(String.valueOf(ex.getMessage()))));
}
} public ResultSet ExecQuery(String sql)
{
try
{
if(rs != null)
rs.close();
conn = ds.getConnection();
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
}
catch(SQLException ex)
{
System.err.println("SqlAction.ExecQuery:".concat(String.valueOf(String.valueOf(ex.getMessage()))));
}
return rs;
} public void ExecUpdate(String sql)
{
try
{
conn = ds.getConnection();
stmt = conn.createStatement();
stmt.executeUpdate(sql);
closeStmt();
closeConn();
}
catch(SQLException ex)
{
System.err.println("SqlAction.ExecUpdate: ".concat(String.valueOf(String.valueOf(ex.getMessage()))));
}
} public void ExecDelete(String sql)
{
try
{
conn = ds.getConnection();
stmt = conn.createStatement();
stmt.executeUpdate(sql);
closeStmt();
closeConn();
}
catch(SQLException ex)
{
System.err.println("SqlAction.ExecDelete:".concat(String.valueOf(String.valueOf(ex.getMessage()))));
}
} public void closeRs()
{
try
{
if(rs != null)
rs.close();
rs = null;
}
catch(SQLException e)
{
e.printStackTrace();
}
} public void closeCstmt()
{
try
{
if(cstmt != null)
cstmt.close();
cstmt = null;
}
catch(SQLException e)
{
e.printStackTrace();
}
} public void closeStmt()
{
try
{
if(stmt != null)
stmt.close();
stmt = null;
}
catch(SQLException e)
{
e.printStackTrace();
}
} public void closeConn()
{
try
{
if(conn != null)
conn.close();
conn = null;
}
catch(SQLException e)
{
e.printStackTrace();
}
} public void CloseAll()
{
closeRs();
closeStmt();
closeCstmt();
closeConn();
}
}