• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

commit() and rollback() problem!

 
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello All,
I am still having problems with my code.
I want to be able to insert data from a file into a database but when i spell one of the column names wrong (on pupose), it inserts the data that is correct then thows the exception, I dont want this as I want the exception to be thown first. If all the names are correct then go ahead and insert.
I ahve tried the commit() and rollback() methods but I am still getting the same responce.
I dont know what I am doing wrong so could someone please help me?
Thanks Ben
here is my code:


I have tried print out before the preparredStatement and the executeUpdate statmnet and this is the output:
prepare
one
two
one
two
one
two
one
two
one
two
one
two
one
two
one
two
one
two
one
two
prepare
one
two
one
two
one
two
one
two
one
two
one
two
one
two
one
two
one
two
one
two
prepare
one
two
one
two
one
two
one
two
one
two
one
two
one
two
one
two
one
two
one
two
prepare
one
java.sql.SQLException: [Microsoft][ODBC SQL Server Driver][SQL Sever] Invalid column name 'Postcod'.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So what you're saying is that even though you get the SQLException and rollback() is called, if you go and look at the database, you find that the updates have been executed anyway?
 
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just a thought...
I noticed you are using the jdbc-odbc bridge driver to connect to a SQLServer. Perhaps it does not support transactions. Although I would think that if that was the case, the calls to setAutoCommit()/commit()/rollback() would generate exceptions but maybe not.
In any case, you should consider using the SQLServer JDBC driver. It should give you more features, boost performance over the jdbc-odbc bridge driver, and possibly solve your problem here with transaction management.
 
ben riches
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
so What changes should I make?
Could you give me an example?
Thanks
Ben
 
Blake Minghelli
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by ben riches:
so What changes should I make?
Could you give me an example?


I'm assuming you are asking how to change the driver you are using:
1. Download the SQLServer JDBC driver from Microsoft and install it.
2. Make sure the jar file(s) are included in your CLASSPATH.
3. Change your url appropriately. I believe your new url would be something like:
4. Change your Driver class:
That should be all you need to change, but double check the docs that come with the JDBC driver because I actually don't work with SQLServer so I can't guarantee the accuracy of my statements.
 
ben riches
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello,
I have downloaded the driver you told me to.
What does the part //[dbserver_ip]:[port] do does this stay the same all the time?
Also how do I connect to my database? Do I have to name my datasouce name as I did before like below?

Also I get an exception saying:
java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver
Thanks Ben
Thanks Ben
[ March 09, 2004: Message edited by: ben riches ]
 
Blake Minghelli
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Substitute [dbserver_ip] with the actual ip address of your SQLServer. Substitute [port] with the actual port on the database server that you connect to (I believe the default for SQLServer is 1433).
Using the SQLServer JDBC driver eliminates the need for you to create an ODBC DSN.
The ClassNotFoundException means that the SQLServer JDBC driver jar is not in your CLASSPATH. After you install the drivers make sure that mssqlserver.jar is specified in your CLASSPATH. For example, make sure that you have "<install_dir>\lib\mssqlserver.jar" (substitute <install_dir> with the actual installation directory) in your CLASSPATH. There might be other jar files in the lib directory that you need to include too.
 
He got surgery to replace his foot with a pig. He said it was because of this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic