Hello
Can someone get me started in the effert to fix this SQL statement to be excepted to create a table in a derby embeded db?
public boolean createTables(Connection conn) throws FileNotFoundException, IOException {
System.out.println("in createTables:");
boolean createdTables = false;
Statement stmt=null;
try {
String thisTable=ModelUtils.getXMLResource("createAdminTable");
System.out.println("thisTable sql String: /n"+thisTable);
stmt = (Statement) conn.createStatement();
//System.out.println("the statement: /n"+stmt);
stmt.execute(thisTable);
createdTables=true;
} catch (SQLException ex) {
Logger.getLogger(ConnectDerbyDAO.class.getName()).log(Level.SEVERE, null, ex);
System.out.println("sql is wrong \n");
ex.printStackTrace();
}finally{
}
/*
for (int i = 0; i < schoolofdbTables.length; i++) {
PreparedStatement ps = null;
try {
//System.out.println("array:table: " + schoolofdbTables[i]);
//System.out.println("table string: " + ModelUtils.getXMLResource(schoolofdbTables[i]));
ps = (PreparedStatement) conn.prepareStatement(ModelUtils.getXMLResource(schoolofdbTables[i].trim()));
System.out.println("table preparedStatement : " + ps);
ps.execute();
createdTables = true;
ps.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
}
*
*/
return createdTables;
}
error output
run:
driver name from xml: org.apache.derby.jdbc.EmbeddedDriver
in createTables:
thisTable sql String: /n CREATE TABLE admin (
admin_uid VARCHAR(11) PRIMARY KEY,
admin_password VARCHAR(11),
admin_lname VARCHAR(20),
admin_mname VARCHAR(20),
admin_fname VARCHAR(20),
admin_gender VARCHAR(1),
admin_age INT,
admin_start_date DATE,
admin_end_date DATE,
admin_address VARCHAR(20),
admin_state VARCHAR(2),
admin_zip INT,
admin_area_code INT,
admin_phone INT,
admin_pay_rate INT )
Exception in thread "main" java.lang.NullPointerException
at model.dao.ConnectDerbyDAO.createTables(ConnectDerbyDAO.java:158)
at model.dao.ConnectDerbyDAO.createDatabase(ConnectDerbyDAO.java:145)
at model.dao.ConnectDerbyDAO.<init>(ConnectDerbyDAO.java:80)
at model.dao.ConnectDerbyDAO.<init>(ConnectDerbyDAO.java:68)
at model.dao.DerbyDAOFactory.buildDB(DerbyDAOFactory.java:20)
at view.Main.main(Main.java:37)
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
error encluded to show errors in sql
run:
driver name from xml: org.apache.derby.jdbc.EmbeddedDriver
in createTables:
Exception in thread "main" java.lang.NullPointerException
thisTable sql String: /n CREATE TABLE admin (
at model.dao.ConnectDerbyDAO.createTables(ConnectDerbyDAO.java:158)
admin_uid VARCHAR(11) PRIMARY KEY,
at model.dao.ConnectDerbyDAO.createDatabase(ConnectDerbyDAO.java:145)
admin_password VARCHAR(11),
at model.dao.ConnectDerbyDAO.<init>(ConnectDerbyDAO.java:80)
admin_lname VARCHAR(20),
at model.dao.ConnectDerbyDAO.<init>(ConnectDerbyDAO.java:68)
admin_mname VARCHAR(20),
at model.dao.DerbyDAOFactory.buildDB(DerbyDAOFactory.java:20)
at view.Main.main(Main.java:37)
admin_fname VARCHAR(20),
admin_gender VARCHAR(1),
admin_age INT,
admin_start_date DATE,
admin_end_date DATE,
admin_address VARCHAR(20),
admin_state VARCHAR(2),
admin_zip INT,
admin_area_code INT,
admin_phone INT,
admin_pay_rate INT )
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
Thank you.