0

When I put my data onto MSAccess, it goes there with dollar signs before it. Here is my relevant code:

try (Connection conn = DriverManager.getConnection(

    "jdbc:ucanaccess://" + dbPath  
 +   ";newdatabaseversion=V2010"
 )) {
         DatabaseMetaData dmd = conn.getMetaData();
         try (ResultSet rs = dmd.getTables(null, null, tableName, new String[] { "TABLE" })) {

        try (Statement s = conn.createStatement()) {
            s.executeUpdate("CREATE TABLE " + tableName +" (Row COUNTER PRIMARY KEY, aColumn NUMBER , bColumn NUMBER)");
            System.out.println("Table " + tableName + " created.");
        }

 }
 conn.close();
}


}
  catch (Exception f){
  f.printStackTrace();
  }
...
 try{

    statement.execute("DISABLE AUTOINCREMENT ON " + tableName );
    statement.executeUpdate("INSERT INTO " + tableName
    + " ( Row, aColumn, bColumn)"
    + " VALUES ( "+(i+1)+", "+a+", "+b+")");
                    System.out.println("row " + i);
                    }
 catch (Exception f ){
                    f.printStackTrace();
                }

When I input 1, 2, 3, and 4 as my values, the graph displays the following: https://puu.sh/weGuX/3000d456bb.png

Any suggestions as to why this would be would be much appreciated, thank you.

Evan
  • 193
  • 9
  • I hope you don't get the tableName from a User-Input – Felix Jun 08 '17 at 20:51
  • I do, is that a problem? – Evan Jun 08 '17 at 20:59
  • A User could manipulate the SQL-Statement trough that. For example, trough that Input I could execute a DROP DATABASE Statement. https://en.wikipedia.org/wiki/SQL_injection – Felix Jun 08 '17 at 21:20
  • How should I go about creating a table then? – Evan Jun 08 '17 at 21:23
  • Use PreparedStatements. The Base-Query (the Query you create the PreparedStatement with) should not contain any variable. For every Variable you want to use, you should place a `?` in the Query and set the value via `PreparedStatement.set___(int, ___)`. Unfortunately you can only use Placeholders for Values (e.g. in INSERT, UPDATE, WHERE-Clause) and not for Table-, or Columnnames. Take a look at this: https://stackoverflow.com/questions/1677465/how-do-i-sanitize-sql-without-using-prepared-statements – Felix Jun 08 '17 at 21:41
  • `NUMBER` in UCanAccess DDL maps to the `Currency` field type in Access, while in the Access UI the default "Number" type is "Long Integer". If you want to create a long integer column then use the DDL keyword `LONG`. – Gord Thompson Jun 08 '17 at 22:41

1 Answers1

0

NUMBER in UCanAccess DDL maps to the Currency field type in Access, while in the Access UI the default "Number" type is "Long Integer". If you want to create a long integer column then use the DDL keyword LONG.

Gord Thompson
  • 116,920
  • 32
  • 215
  • 418