社区
Web 开发
帖子详情
今天最后一个问题!关于executeUpdate的,在线等侍!顶者有分
pdw2009
2004-08-24 04:18:44
现在要修改数据库里的某条记录我不想用PreparedStatement,能不能直接用executeUpdate来更新呢
如果能,请你给出一条executeUpdate的例子,如果不能,请你给出PreparedStatement的使用方法。
谢谢,大家的关照真,没有csdn的朋友,可能我无法进行这个行业。。。
...全文
369
10
打赏
收藏
微信扫一扫
点击复制链接
分享
下载分享明细
分享
举报
写回复
10 条
回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
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
期侍中,,,,
打赏
举报
回复
赞
相关推荐
关于
executeUpdate
()返回值
问题
今天
debug
的
时候发现使用truncate
的
时候
executeUpdate
()
的
返回值是0
,
让我十分费解
,
因为之前使用update语句debug出来
的
返回值是需要更新
的
条数
,
后来问了群里老哥
,
老哥说是因为truncate是DDL语句
,
返回值为0时表示...
执行
executeUpdate
();
等
方法误传入了sql参数导致运行出错
的
细节
问题
问题
源头 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘?,?,?,?)’ at line 1 您
的
SQL语法有错误;检查与MySQL...
关于
executeUpdate
方法返回
的
值
问题
今天
在项目中出现了
一个
问题
,
delete 语句使用
executeUpdate
方法后
,
如果是更新一条数则返回1
,
但是更新一条以上数据就出现返回0
的
问题
,
我一直以为
executeUpdate
返回更新
的
条数是错误
的
?带着疑问我们查看源码: @...
关于
DEBUG到ps.
executeUpdate
();这一步不执行
的
问题
今天
下午在公司debug
的
时候
,
发现两个表
的
一直走到SQL执行那一层
的
时候不往下执行了
,
原因是这两个表我进行查询操作时候添加了for update语句
,
然后没有commit
,
导致表一直处于锁住
的
状态
,
不能执行语句
,
我把两个...
奇葩
!
PreparedStatement.
executeUpdate
执行之后
的
问题
s.YangHao.org ...分 类PHP开源PHP基础PHP框架C#语言MSSQL基础ASP.NETHTML(CSS)javascriptajaxASPJava SEJava MEJava WebJava EEMySQLFlexSilverlightFlash技术Flash开发VB.NET.NET Fra
发帖
Web 开发
微信扫一扫
点击复制链接
分享社区
下载分享明细
8.0w+
社区成员
34.1w+
社区内容
Java Web 开发
社区管理员
加入社区
帖子事件
创建了帖子
2004-08-24 04:18
社区公告
暂无公告