samedi 9 mai 2015

Sqlite Table Create Syntax Error

I am just trying to get text from a JtextField and I want to implement it inside a sql injection to create a table. Here is my code:

try {
  Class.forName("org.sqlite.JDBC");
  conni  = DriverManager.getConnection("jdbc:sqlite://C://Users//Asus//Dropbox//Admin.sqlite");

  stmt = conni.createStatement();

  String sql =  "CREATE TABLE" + projectname.getText() + 
               "(ID INT PRIMARY KEY     NOT NULL,"  + 
               " NAME           TEXT    NOT NULL, " +
               " EstQuantity            INT     NOT NULL, " +
               " UnitPrice        CHAR(50), " +
               " TotalPrice         REAL)"; 

  stmt.executeUpdate(sql);
  stmt.close();
  conni.close();
} catch ( Exception e ) {
  System.err.println( e.getClass().getName() + ": " + e.getMessage() );
  System.exit(0);
}
JOptionPane.showMessageDialog(null, "Project Created!");

This is the basic structure.

When I input my table name it says java.sql.SQLException: near "(my input)CREATE": syntax error

Aucun commentaire:

Enregistrer un commentaire