Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JDBC-ODBC

 
Patrick Mugabe
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic