Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jdbc batch

 
avijit majumder
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can I make multiple select Query in a batch

String st1="select password from login where id='"+1+"'";
String st2="select password from login where id='"+2+"'";

java.sql.Connection con=..............;
java.sql.Statement st=con.createStatement();
st.addBatch(st1);
st.addBatch(st2);
java.sql.ResultSet rs=st.executeBatch(); // BUT it return an int Array. int a[]=st.executeBatch();
/*
Now how can I find the RESULT in my ResultSet rs???
pl z help!!!

*/
 
Jaydeep Mazumdar
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please use tags to post code.

In your case, you can change the SQL to:



That way you will avoid invoking multiple sql statements in a batch.
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Avjit,

Welcome to Javaranch

Now how can I find the RESULT in my ResultSet rs???
pl z help!!!


Why do you need a result Set for Batch ? Usually Batch is used to execute series of insert/update/delete statements pertaining to a single transaction.Either you commit at end or rollback on failure. Thus making it behave as single transaction.
Result Set object maintains cursor to navigate in the records fetched from DB. Its not useful in updateBatch case.
 
manepalli rajesh
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,
our requirement is
we have a list of mailids in oracle table. we want to read all the mailids and wants to send a mail to them (i have a code to send mails). but this should be happen on daily basis.i dont know how to do this.can somebody help me in this.

ton of thanks.



 
Sivaraman Lakshmanan
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rajesh,
Just query your database for the email ids something like "Select * from emailtable where conditon". Once you execute the above statement you get the resultset. Loop through the resultset and get all the emails ids and store them in a StringBuffer seperated by ";". Then use this in your mailer programme.

Hope this helps.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
manepalli rajesh,

in the future, please do not post unrelated questions into an existing topic. Your question has nothing to do with the original topic, and we now have a discussion that deals with two unrelated issues, which is something we try hard to avoid.
 
Rene Larsen
Ranch Hand
Posts: 1179
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jaydeep Mazumdar wrote:Please use tags to post code.

In your case, you can change the SQL to:



That way you will avoid invoking multiple sql statements in a batch.

Just be aware of that Oracle has a max param limit of 1000 in each IN clause...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic