更新数据库中的记录出错!!!!

dcren521 2003-08-26 10:21:21
我想用JSP更新数据库中的记录,字段templateid为number类型,我本想给其赋予一个随机整数,但现在测试时,赋予一个整数都出错,不知道何故。请各位大哥指教!

<!--test.jsp-->
<%@ page language="java" import="java.io.*,java.sql.*,javax.sql.* ,javax.naming.*"%>
<%@ page contentType="text/html;charset=gb2312" %>
<html>
<body>
<%
String sDBDriver = "oracle.jdbc.driver.OracleDriver";
String sConnStr = "jdbc:oracle:thin:@name:1521:dbname";

Connection conn = null;
ResultSet rs = null;
Statement stmt = null;

try
{
Class.forName(sDBDriver);
conn=DriverManager.getConnection(sConnStr,"dbuser","password");
String sqlupdate="update m_company_base_info set templateid=5 where name='"+"hjhm"+'";
rs = stmt.executeUpdate(sqlupdate);
}
catch(Exception e)
{
out.println(e.getMessage());
}
finally
{
stmt.close();
conn.close();
}
%>
</body>
</html>
...全文
32 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
dcren521 2003-08-26
  • 打赏
  • 举报
回复
hjhm是数据库中的一个字段的值
类型为vchar
还是不行呀
gisgeoboy 2003-08-26
  • 打赏
  • 举报
回复
hjhm没有传递过来的值,给一个固定的只也可以.
zhaoxichao 2003-08-26
  • 打赏
  • 举报
回复
String sqlupdate="update m_company_base_info set templateid=5 where name='"+"hjhm"+'";
改成
如果hjhm是一个变量
String sqlupdate="update m_company_base_info set templateid=5 where name='"+hjhm+"'";
如果是一个字符串
String sqlupdate="update m_company_base_info set templateid=5 where name='hjhm'";

rs = stmt.executeUpdate(sqlupdate);
改成
stmt.executeUpdate(sqlupdate);
flyshp 2003-08-26
  • 打赏
  • 举报
回复
yes


try ..........
renzy205 2003-08-26
  • 打赏
  • 举报
回复
String sqlupdate="update m_company_base_info set templateid=5 where name='"+"hjhm"+"'";
少个"
cainiao_2000 2003-08-26
  • 打赏
  • 举报
回复
String sqlupdate="update m_company_base_info set templateid=5 where name='"+"hjhm"+'";
这条语句中的最后'";改为"'";
完整:
String sqlupdate="update m_company_base_info set templateid=5 where name='"+"hjhm"+"'";
wssg 2003-08-26
  • 打赏
  • 举报
回复
String sqlupdate="update m_company_base_info set templateid=5 where name='"+"hjhm"+"'";

or

String sqlupdate="update m_company_base_info set templateid=5 where name='"+hjhm+"'";
flyshp 2003-08-26
  • 打赏
  • 举报
回复
String sqlupdate="update m_company_base_info set templateid=5 where name='"+"hjhm"+'";

hjhm 是什么?? 如果参数固定的话 好像有毛病

直接写 name='"+hjhm+"';
dcren521 2003-08-26
  • 打赏
  • 举报
回复
补充一下提示出错为
Full compiler error(s):
C:\bea7\user_projects\ainfo\mydomain\myserver\.wlnotdelete\DefaultWebApp_DefaultWebApp_5823534\jsp_servlet\__test.java:107: unclosed character literal
String sqlupdate="update m_company_base_info set templateid=5 where name='"+"hjhm"+'"; //[ /test.jsp; Line: 18]
^
C:\bea7\user_projects\ainfo\mydomain\myserver\.wlnotdelete\DefaultWebApp_DefaultWebApp_5823534\jsp_servlet\__test.java:108: incompatible types
found : int
required: java.sql.ResultSet
rs = stmt.executeUpdate(sqlupdate); //[ /test.jsp; Line: 19]
^
2 errors

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧