社区
Web 开发
帖子详情
今天最后一个问题!关于executeUpdate的,在线等侍!顶者有分
pdw2009
2004-08-24 04:18:44
现在要修改数据库里的某条记录我不想用PreparedStatement,能不能直接用executeUpdate来更新呢
如果能,请你给出一条executeUpdate的例子,如果不能,请你给出PreparedStatement的使用方法。
谢谢,大家的关照真,没有csdn的朋友,可能我无法进行这个行业。。。
...全文
455
10
打赏
收藏
今天最后一个问题!关于executeUpdate的,在线等侍!顶者有分
现在要修改数据库里的某条记录我不想用PreparedStatement,能不能直接用executeUpdate来更新呢 如果能,请你给出一条executeUpdate的例子,如果不能,请你给出PreparedStatement的使用方法。 谢谢,大家的关照真,没有csdn的朋友,可能我无法进行这个行业。。。
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用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
打赏
举报
回复
期侍中,,,,
关于
execute
Update
方法返回的值
问题
本文深入探讨了
execute
Update
方法在处理SQL语句时的行为,特别是针对更新和删除操作返回的行数
问题
。通过源码分析,解释了为何在某些情况下,即使多行数据被更新或删除,方法也可能返回0。
Hibernate中
execute
Update
的缓存
问题
在处理业务逻辑时,涉及Hibernate的
execute
Update
方法修改product_sale_stock和pss_total_stock表,但发现数据完整性未得到保持。原因是
execute
Update
虽执行了HQL,但在一级缓存中未更新数据,导致后续查询仍获取到旧值。解决方案是将第三步的HQL查询改为SQL查询,以确保数据一致性。
execute
,
execute
Query和
execute
Update
的区别
本文详细介绍了JDBC中执行SQL语句的三种方法:
execute
、
execute
Query和
execute
Update
的区别及应用场景,并通过示例代码展示了如何使用这些方法进行数据库操作。
execute
与
execute
Update
的区别
本文总结了JDBC中
execute
和
execute
Update
的相同点与不同点。相同点是二者都可执行增加、删除、修改操作。不同点在于,
execute
能执行查询语句并通过getResultSet取结果集,返回boolean类型;而
execute
Update
不能执行查询语句,返回int类型,表示受影响的数据条数。
jdbc 中 excute
execute
Update
的用法作用
本文详细介绍了Java中通过Statement接口执行SQL语句的三种方法:
execute
Query、
execute
Update
和
execute
。针对不同类型的SQL语句(如SELECT、INSERT、
UPDATE
、DELETE等),文章解释了何时使用哪种方法,并介绍了如何处理这些方法产生的结果。
Web 开发
81,111
社区成员
341,723
社区内容
发帖
与我相关
我的任务
Web 开发
Java Web 开发
复制链接
扫一扫
分享
社区描述
Java Web 开发
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章