今天最后一个问题!关于executeUpdate的,在线等侍!顶者有分

pdw2009 2004-08-24 04:18:44
现在要修改数据库里的某条记录我不想用PreparedStatement,能不能直接用executeUpdate来更新呢

如果能,请你给出一条executeUpdate的例子,如果不能,请你给出PreparedStatement的使用方法。


谢谢,大家的关照真,没有csdn的朋友,可能我无法进行这个行业。。。
...全文
405 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
power17 2004-08-24
  • 打赏
  • 举报
回复
不会是单引号或是其它什么地方出错了吧。

建议先把SQL语句写在查询分析器上运行一下,运行无误后放到jsp中去。
aoplo 2004-08-24
  • 打赏
  • 举报
回复
prepareStatement方式:

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url="jdbc:odbc:user_db";
Connection con=DriverManager.getConnection(url,"insher","insher");
PreparedStatement stm=con.prepareStatement("insert into message values(?,?,?,?,?)");
stm.setString(1,title);
stm.setString(2,name);
stm.setString(3,mail);
stm.setString(4,datetime);
stm.setString(5,content);
建议用executeUpdate方式!
pdw2009 2004-08-24
  • 打赏
  • 举报
回复
<%
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
Connection conn=null;
try{

//Connection conn=DriverManager.getConnection("jdbc:mysql://localhost/test");
conn=DriverManager.getConnection("jdbc:mysql://192.168.0.217/courthouse?user=root&password=&useUnicode=true&characterEncoding=");
}catch(Exception e){
System.out.println("ERROR"+e);
}
PreparedStatement pstmt=conn.PreparedStatement("update b_ryxx set MC=?,YX=?,ISFJY=?,XCBM=?,password=? where DM=?");
%>

这是我原来写的,但却出现以下错误,大家看看是什么原因
----------------------------------------------------------------
symbol : method PreparedStatement (java.lang.String)
location: interface java.sql.Connection
PreparedStatement pstmt=conn.PreparedStatement("update b_ryxx set MC=?,YX=?,ISFJY=?,XCBM=?,password=? where DM=?");
aoplo 2004-08-24
  • 打赏
  • 举报
回复
<jsp:useBean id="wu" scope="page" class="conn.jdbc" />//数据库连接bean
<%
Connection con = wu.getConn();
Statement stmt = con.createStatement() ;
String sql = ".............";
ResultSet rs = stmt.executeUpdate(sql) ;
%〉
wangwei8117 2004-08-24
  • 打赏
  • 举报
回复
sql="update dbName set xx='abc' where xx=?
stmt.execute(sql);就可以,不容易出现错误的!
runningww 2004-08-24
  • 打赏
  • 举报
回复
当然可以了
String url = "jdbc:microsoft:sqlserver://127.0.0.1:1433";
Connection con = null;
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
con = DriverManager.getConnection(url,"sa","");
Statement stmt = con.createStatement();
stmt.executeUpdate(sql);
zyfdanny 2004-08-24
  • 打赏
  • 举报
回复
Connection con = DriverManager.getConnection("jdbc:odbc:dbname","","");
Startement stmt = con.CreateStatement();
stmt.executeUpdate("update table set xx =xx");
con.close();
一点晴 2004-08-24
  • 打赏
  • 举报
回复
PreparedStatement的使用方法:

sql="update books set price=? where id=?";//例子SQL语句更新某本书的价格

PreparedStatement pst=conn.prepareStatement(sql);
pst.setInt(1,"20");//对应SQL中第1个?如果是字符串型数据则是.setString() 看API文档
pst.setInt(2,"133");////对应SQL中第2个?
pst.executeUpdate();
pst.close();
一点晴 2004-08-24
  • 打赏
  • 举报
回复

非预便宜的statement
Statement st=conn.createStatement();
st.executeUpdate(sql);

pdw2009 2004-08-24
  • 打赏
  • 举报
回复
期侍中,,,,

81,091

社区成员

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

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