与返回值一起使用时,行未更新 [英] row not updated when used with return values
问题描述
我有一个SQL查询
从旧表中选择*(更新tbl set col1 = 2)
查询在命令行中运行正常,但与jdbc一起使用时,它会正确返回值,但不会更新值
这里是一段代码片段
< pre lang =java>
ResultSet rs = st.executeQuery(sql);
i正在以正确的方式进行吗?
2)例如
i表中有4列
areaid,ROle,approverNo,用户名
1,role1,1,aaa
1,role2,1,sss
1,role1,2,fgfg
1,role1,3,tyty
1,role2,2,ghg
1,role1,4,sdss
和soo现在如果我添加值1,role1,(从tbl中选择Count(*),其中areaid = 1和role = role1),dfdf它工作正常,当我删除时会出现什么问题让我说1,role1,3,tyty我将不得不重新分配approvernum,以及当我更新角色时的查询? div class =h2_lin>解决方案
您好,
您可以尝试提交连接,以确保数据被提交到数据库。
你可以参考这个链接 http://www.tutorialspoint.com/jdbc/commit-rollback.htm [ ^ ]
好的,请详细参阅此链接: JDBC-锁使用选换更新犯规工作一排,http://stackoverflow.com/questions/4682871/jdbc-lock-a-row-using-select-for -update-doesnt-work [ ^ ]
两次不要问同一个问题。编辑你的问题。
从旧表中选择*(更新tbl set col1 = 2)
这是一种延迟语法。正如我已经告诉过你的那样,编写一个存储过程并分两步完成。或者只是尝试执行此操作:
update tbl set col1 = 2 go select from old table
这是真正的查询吗? db2接受旧表作为没有[]的表名?这两个表是不相关的吗?
i have a sql query
select * from old table (update tbl set col1= 2)
query works fine in command line but when used with jdbc it return the value correctly but does not update the values
here is a code snippet
<pre lang="java"> ResultSet rs = st.executeQuery(sql);
i am doing it the proper way?
2) e.g.
i have a 4 column in table
areaid,ROle,approverNo,username
1,role1,1,aaa
1,role2,1,sss
1,role1,2,fgfg
1,role1,3,tyty
1,role2,2,ghg
1,role1,4,sdss
and soo on now if i add a value 1,role1,(select Count(*) from tbl where areaid=1 and role=role1),dfdf it is working fine , what will be the query when i delete let say "1,role1,3,tyty" will i have to reassign approvernum ,and the query when i will update the role?
Hello,
You can try committing the connection which will make sure that the data is being committed to the database.
You can refer this link http://www.tutorialspoint.com/jdbc/commit-rollback.htm[^]
Okay, Refer this link in detail : http://stackoverflow.com/questions/4682871/jdbc-lock-a-row-using-select-for-update-doesnt-work[^]
Don't ask the same question twice. Edit your question.
"select * from old table (update tbl set col1= 2)"
This is a retarded syntax. As I've told you already, write a stored procedure and do it in two steps. Or just try to execute this:
update tbl set col1= 2 go select * from old table
Is this the real query ? db2 accepts old table as a table name without [] ? The two tables are unrelated ?
这篇关于与返回值一起使用时,行未更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!