Click here to Skip to main content
15,888,984 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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?
Posted
Updated 16-Jan-14 5:52am
v2

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[^]
 
Share this answer
 
Comments
agha_ali22 15-Jan-14 4:38am    
but i am not using it in transition
 
Share this answer
 
Comments
agha_ali22 15-Jan-14 7:23am    
Please if you can give me some example with my scenario.
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 ?
 
Share this answer
 
Comments
Jörgen Andersson 16-Jan-14 7:45am    
The square brackets [] are MS specific, MySQL uses the backtick "`", while ANSI SQL specifies double quotes "".
But in this case I wouldn't put any significance to the name "old table"
agha_ali22 16-Jan-14 11:34am    
as i stated ealier that this query "select * from old table (update tbl set col1= 2) " is working fine in db2 command line ,actually i am working on an ibm product it creates db by itself so i was little bit of hesitant in creating stored procedure , but now i will, please see the updated question i have another problem
Ask a new question to ask a new question. This is confusing.

"when i delete let say "1,role1,3,tyty" will i have to reassign approvernum ,and the query when i will update the role?"

Foreign keys should stop you from deleting values that are used in other tables. If not, fix your DB. Once that is so, you should NEVER have ids that you need to change based on other changes in your DB.
 
Share this answer
 
Comments
agha_ali22 16-Jan-14 16:46pm    
Sorry, Actually Approvernum is not used in any table , it is there to tell that this is the 3rd approver of role1(1,role1,3,tyty).
agha_ali22 16-Jan-14 18:38pm    
stored procedures are created :) , all i wanted to know for sake of info that why select * from old table (update tbl set col1= 2) is working fine in command line tool that comes with db2, the same query when executed does not work in jdbc
Christian Graus 16-Jan-14 18:47pm    
I have no clue. Obviously it has to do with the framework it's running inside.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900