INSERT SQL problem

If i do two insert statements, only the first statement seems to be commited. If i do three, only the first two are commited etc. Autocommit is set to true and i have tried manually commiting the statement. The only way i can get all insert statement to commit is by closing the connection (which i dont want to do).

Does anyone know how to fix this problem? I saw a similar post before but no real solution.

[421 byte] By [tom_eng85a] at [2007-10-2 6:04:22]
# 1
Can you show us your code?
Marcelo9a at 2007-7-16 13:04:47 > top of Java-index,Java Essentials,Java Programming...
# 2
So did you solve you problem connecting to the database?If so, then you should respond to your other posting so people don't waste their time wondering if you still need help.
camickra at 2007-7-16 13:04:47 > top of Java-index,Java Essentials,Java Programming...
# 3

Thanx for your ever so helpful comments again (*****). Yes i solved my previous problem but since noone else expressed an interest in it how am i to know anyone wants to know how i solved it.

public void openConnection() {

try {

// Register the JDBC driver for Access

DriverManager.registerDriver(new sun.jdbc.odbc.JdbcOdbcDriver());// Open a connection to the database

conn = DriverManager.getConnection(url, username, password);// replace with string variable url

conn.setAutoCommit(true);//already default value, not needed?

String keyword = "football";

addKeyword(keyword);

Statement stmt = conn.createStatement();

String SQL = "INSERT INTO tblKeywords (Keyword) VALUES ('football')";

stmt.executeUpdate(SQL);

//stmt.close();

stmt.executeUpdate("INSERT INTO tblKeywords (Keyword) VALUES ('i')");

conn.commit();

stmt.executeUpdate("INSERT INTO tblKeywords (Keyword) VALUES ('o')");

conn.commit();

stmt.close();

conn.close();

} catch (SQLException e) {

System.err.println("Error opening connection to database: ");

System.err.println(e.getMessage());

// make sure we've not left a connection open

closeConnection();

}

}

tom_eng85a at 2007-7-16 13:04:47 > top of Java-index,Java Essentials,Java Programming...
# 4

> Thanx for your ever so helpful comments again (*****). Yes i solved my previous problem

Well then it would appear my suggestions where indeed helpfull. Maybe I forced you to do a little reading or searching on your own, but you have now improved your skill set.

> but since noone else expressed an interest in it how am i to know anyone wants to know how i solved it.

The point is you should always post a closing comment, so people don't waste their time responding to a posting when the poster has already solved the problem. Is this not logical?

camickra at 2007-7-16 13:04:47 > top of Java-index,Java Essentials,Java Programming...