Results 1 to 3 of 3

Thread: Access record not being added

  1. #1
    Join Date
    Oct 2003
    Posts
    1

    Angry Access record not being added

    I'm just trying to get started with servlets and JDBC and I am using MS Access as the database. I am having a lot of trouble with Access. Here is the scenario. Two days ago, the code listed below did not write the last record to the database, I struggled a long time trying to figure out what was happening. I finally gave up and got some sleep. The next day the exact same code worked, all records written. Went ahead working on some other items, knowing that the database connection and such were working. Well today the code does not work. The last record is not added! Specifically this line does not seem to be added "INSERT INTO testTable2 VALUES(789, 'name3')"
    . Please note that in the java code the println statement comes after the insert into statement and the println statement is showing up on screen. I really can't continue on until this gets resolved. Can somebody suggest some reason why this is not working? Thanks.

    To keep this short, I will paste only the necessary part, skipping the error handling section.

    import java.sql.*;

    public class BuildTables {
    public static void main(String[] args) {
    try {
    String username = "guest";
    String password = "guest";
    String url = "jdbcdbc:db2";
    String driver = "sun.jdbc.odbc.JdbcOdbcDriver";

    String[] SQLStatements = {
    "CREATE TABLE testTable2 (Num INT NOT NULL PRIMARY KEY, name CHAR(20))",
    "INSERT INTO testTable2 VALUES(123, 'name1')",
    "INSERT INTO testTable2 VALUES(456, 'name2')",
    "INSERT INTO testTable2 VALUES(789, 'name3')"
    };

    Class.forName(driver);
    Connection conn = DriverManager.getConnection(url, username, password);
    Statement stmt = conn.createStatement();
    for(int i = 0; i < SQLStatements.length; i++) {
    stmt.executeUpdate(SQLStatements[i]);
    System.out.println(SQLStatements[i]);
    }
    }

  2. #2
    Join Date
    Jan 2003
    Location
    UK
    Posts
    277
    what happens if you try and INSERT say 10 rows ? Is it always the last one ?

    Why is name a CHAR datatype instead of a VARCHAR ??

  3. #3
    Join Date
    Oct 2003
    Posts
    8
    Question; Are you getting information from one table to another??

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •