Multiple executeUpdates() issue

Hi Friends

i am having a problem for which i need your suggestion.

i have a code as below

conn = ConnectionFactory.getInstance().getConnection();

stmt = conn.createStatement();

stmt.executeUpdate("INSERT INTO Client ( clientPk, provincePk, countryPk, statusPk, branchPk, salutation, weight, heightMeasurementType, weightMeasurementType ) "+"VALUES (55, '1', ', '66', 1, 1 );");

stmt.executeUpdate("INSERT INTO NurseClientMapping ( userPk, clientPk, sortOrder ) VALUES ('30251', '55', '1');");

stmt.executeUpdate("INSERT INTO clientcareplan ( clientCarePlanPk,carePlanPk,clientPk,statusPk,createdByUserPk,lastupdated,sourceTypePk) VALUES ('25,'1',55,'0',30251,DATE_SUB(SYSDATE(),INTERVAL 11 DAY),'1');");

stmt.executeUpdate("INSERT INTO clientsessioninfo (sessionPk,clientCarePlanPk,clientPk,createdByUserPk,sessionName,startTime,endTime,reminderTime,statusPk,syncStatusPk,lastupdated,sourceTypePk) VALUES (100,25,55,30251,'Wake-up','05:00:00','07:00:00','10','0','2',DATE_SUB(SYSDATE(),INTERVAL 11 DAY),'1');");

stmt.executeUpdate("INSERT INTO clientSurveyPrescription (clientSurveyPrescriptionPk,,lastupdated,sourceTypePk) "VALUES (1000,25,55,30251,'0','2',SYSDATE(),'1');");

i am having multiple queries to execute. i am using this approach of executing all the queries one at a time. is this approach correct to be followed.

please let me know is this correct. waiting for positive reply from your side.

Thanks & Regards

Vikram K

[1559 byte] By [vikenga] at [2007-11-27 10:49:50]
# 1

Does it work?

manuel.leiriaa at 2007-7-29 11:21:42 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2

First, I believe you dont need a semicolon at the end of your sql statements that appear in your executeUpdate() statements.

Next, I suggest you put your code in a try/catch/finally block and properly close the connection when the code is done (there are examples on line about this).

Next, I suggest putting all executeUpdate statements in a transaction and either commit or rollback as necessary (see connection.setAutoCommit() ).

Last, you should use connection pooling and not DriverManager to get your connection (if you aren't already using connection pooling).

Sorry, cant provide examples.

George123a at 2007-7-29 11:21:42 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3

Hi

i am getting a NullPointerException when i try to execute the code that i have provided.

The first query is itself not executing and i checked the database also data is also not being inserted into the database.

any idea whats going on here. atleast the first execute statement should get executed.

Regards

Vikeng

vikenga at 2007-7-29 11:21:42 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 4

Break this line up into separate lines to see which is returning a null:

FROM

conn = ConnectionFactory.getInstance().getConnection();

TO:

ConnectionFactory connFactory = ConnectionFactory.getInstance();

Connection conn= connFactory.getConnection();

Then either single step through each line, or put System.println() statements above and below all lines to see which is null. I suspect your ConnectionFactory.getInstance() returns null because its not configured correctly. I'm not familiar with ConnectionFactory so I can help any further.

George123a at 2007-7-29 11:21:42 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 5

It looks like as George suggested a connection factory instance is not available or your internal implementation of getConnection is not returning you the connection may the datasource or connection properties is not configured properly. So please debug for each statement.

javashisha at 2007-7-29 11:21:42 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...