Results 1 to 6 of 6
- 07-26-2011, 12:57 PM #1
Member
- Join Date
- May 2011
- Posts
- 97
- Rep Power
- 0
how to call multiple sql statements in java
Hi,
I have to execute a sql statement, based on that result i have to executed i have to fetch another data using select statement, based on the second sql i have to execute create statement, and i have thousands of rows of data to handle, how to accomplish that?
basically the flow is Select --> Select --> create Statements.
Regards
Sandeep
- 07-26-2011, 05:21 PM #2
Senior Member
- Join Date
- Feb 2010
- Posts
- 128
- Rep Power
- 0
Java Code:Connection conn = DriverManager.getConnection(<path>,<username>,<password>); Statement s = conn.prepareStatement("Select * from <tablename>"); ResultSet rs = s.executeQuery();
so for multiple selects you would just need to replace values in prepareStatament. Or use a String variable and change its values after each executeQuery in prepareStatement.Measuring programming progress by lines of code is like measuring aircraft building progress by weight.
- 07-26-2011, 06:17 PM #3
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
And before you do that, make sure you can't do this as a single SQL.
Or at least merge the two SELECTs.
If all you;re doing is:
because that there should be a single SQL statement, not 3.Java Code:SELECT x FROM y WHERE (some criteria); if (x == somethingOrOther) { SELECT a FROM b WHERE c = x; INSERT INTO n (someColumn) VALUES (a); }
- 07-26-2011, 06:20 PM #4
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,605
- Rep Power
- 5
Just nest your JDBC calls. Keep in mind that only one ResultSet associated with a Statement can be open at the same time.
Lesson: JDBC Basics (The Java™ Tutorials > JDBC(TM) Database Access)
- 07-31-2011, 12:59 PM #5
Member
- Join Date
- Jul 2011
- Posts
- 2
- Rep Power
- 0
This should help. JDBC 2.0 allows you to use the addBatch method, but mysql will not allow multiple queries unles you set that security (allowMultiQueries)property. I hope this helps!
Last edited by DarrylBurke; 07-31-2011 at 03:47 PM. Reason: Spammy signature links removed
- 08-01-2011, 10:13 AM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Similar Threads
-
if statements for multiple variables
By dookie1293 in forum New To JavaReplies: 9Last Post: 06-17-2011, 09:30 AM -
How to call set of sql statements in java?
By sandeep43 in forum JDBCReplies: 5Last Post: 05-31-2011, 06:58 AM -
How to call set of sql statements in java?
By sandeep43 in forum New To JavaReplies: 0Last Post: 05-30-2011, 06:37 AM -
Effect of Multiple Condtitions in if() statements to run time
By kimhonoridez in forum New To JavaReplies: 4Last Post: 12-08-2010, 08:40 AM -
call by value and call by reference in java
By sandeepsai39 in forum New To JavaReplies: 7Last Post: 08-12-2010, 11:03 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks