wood burning stoves 2.0*
The moose likes JDBC and the fly likes JDBC-ODBC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "JDBC-ODBC" Watch "JDBC-ODBC" New topic
Author

JDBC-ODBC

Patrick Mugabe
Ranch Hand

Joined: Jan 08, 2002
Posts: 132
Hi everyone,
Can someone give me an example of how to connect to SQL Server 2000 using Java and do an 'insert' and be able to access the data from the SQL Server Query Analyser.
I have done several programs which are compiling with no errors but then when I go to check for the results I am findind nothing.
Please help...
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

why don't you post your code that isn't working properly and we can give you some suggestions to make it work as you intended.
Jamie
Patrick Mugabe
Ranch Hand

Joined: Jan 08, 2002
Posts: 132
Here is a section of my code that connects to the database:

[ Edited by Dave to fix and format code ]
[ January 30, 2002: Message edited by: David O'Meara ]
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

You need setString(1,...), setString(2,...), setString(3, ...) etc.
At the moment they are 1,2,1,1,1 etc so you are overwriting the first parameter.
I usually do this with an increment so that I can add/remove and re-order attributes without having to redo the indicies constantly.

Dave.
Patrick Mugabe
Ranch Hand

Joined: Jan 08, 2002
Posts: 132
Sorry that was my mistake.
I have already corrected that part and it's still not working.
This is the code:

[ Edited to add code block again ]
[ January 31, 2002: Message edited by: David O'Meara ]
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

There's a bug in either the JDBC-ODBC bridge or Access (not sure which, I'm assuming the bridge) where inserts are not
You can do a search in this forum for other solutions, but you can do these things: Firstly, explicitly commit your transactions. Secondly, perform a small select on the same connection.
I've never had the problem, but I've heard these steps can provide a solution.
Dave.
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

We need more information on the exception thrown. Change your catch block to the following:

let us know what the error message is. About David's suggestion to "Secondly, perform a small select on the same connection." I'm sure this is an access only problem (Access ODBC driver). Never seen it on anything other than MSAccess.
Jamie
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JDBC-ODBC
 
Similar Threads
How can I get old versions of JForum?
Bulk data through JDBC
question about default parameters in stored procedure via JDBC
Connect to db, simple question !!
how to convert .csv files into sql server files using java