Batch statement with sql server 2000 driver

Hi,

I have been using the jdbc bridge and recently upgraded to the sql server 2000 driver. I have some code that was working correctly executing some batch commands. But with the new driver it no longer works. Its throwing errors. Can anyone help? I have tried removing the begin/end statments and that causes a different error to be thrown.

Statement s = db.createStatement();

s.addBatch("Begin");

s.addBatch("use master");

s.addBatch("EXEC sp_addlogin '" + login +"','" + loginAuth + "','testDB'");

s.addBatch("use testDB");

s.addBatch("EXEC sp_grantdbaccess '" + login + "' , '" + login + "'");

s.addBatch("End");

s.executeBatch();

[707 byte] By [mhouser12] at [2007-9-27 16:23:27]
# 1

hi,

I havent worked with MS SQL a lot however by the looks of it seems that you want to execute a stored procedure or a unnamed block. Try the Statement object or the CallableStatement object in which case you will have to write a stored proc which encapsulates all the statements you have written.

addBatch is to run multiple statements like (insert, update) in a single shot thus

saving on the network traffic.

connection.createStatment().execute( "BEGIN ..... END " );

Just look at the JDBC doc. it will give a better idea about when to use Statement, PreparedStatement and CallableStatement objects and when to use a batch.

hope it helps.

venky

venkatesh98 at 2007-7-6 0:41:42 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2

> I have been using the jdbc bridge and recently

> upgraded to the sql server 2000 driver.

i think you maybe are sol...

>Statement s = db.createStatement();

>s.addBatch("Begin");

>s.addBatch("use master");

> s.addBatch("EXEC sp_addlogin '" +

> p_addlogin '" + login +"','" + loginAuth +

> "','testDB'");

>s.addBatch("use testDB");

> s.addBatch("EXEC sp_grantdbaccess '" +

> ntdbaccess '" + login + "' , '" + login + "'");

>s.addBatch("End");

>

>s.executeBatch();

the documentation from microsoft reads...

for both CallableStatement and PreparedStatement

void addBatch (String)

Not Supported

Throws "invalid method call" exception.

is this the error you are seeing?

venkatesh98 at 2007-7-6 0:41:42 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3
What the errors you are getting?
sudha_mp at 2007-7-6 0:41:42 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...