• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Another executeUpdate() ?

 
Nick Neidig
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The class runs without exception, but the values 55 and CD Player do not appear in the Access table Customer1 after I run the class. Thanks for your help.
Nick
package be314;
import java.sql.*;
public class TestUpdate {
public static void main (String args []) {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c = DriverManager.getConnection(
"jdbc dbc:Music");
Statement s = c.createStatement();
s.executeUpdate ("INSERT INTO Customer1 VALUES (55, 'CD Player')");
System.exit(0);
} catch (SQLException bb) {
System.out.println(bb);
System.exit(0);
} catch (ClassNotFoundException cc) {
System.out.println(cc);
System.exit(0);
}
}
}
 
Lu Battist
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is strange. If it is running with no exceptions, the likly cause is that it is not being committed to the database. Try this, c.setAutoCommit(true); right after you get the connection. Also be sure to close your statement and especially the connection after your done with them.
 
Nick Neidig
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks again Lu
I got the results to show up in the database. I experimented with including setAutoCommit(true) and the closing statements in my class and found that the results show up correctly with or without the setAutoCommit(true).
 
Dana Hanna
Ranch Hand
Posts: 227
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think closing the statement was the important part here. Removing the System.exit(0) would have probably worked as well.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic