Could someone look at my Statement stmt? is this error due to improper string creation?
Thanks

public String stmtCreateStudentTable =
            "CREATE TABLE student ("
            + "stu_uid CHAR(11),"
            + "stu_password CHAR(11),"
            + "stu_lname CHAR(20),"
            + "stu_mname CHAR(20),"
            + "stu_fname CHAR(20),"
            + "stu_gender CHAR(1),"
            + "stu_age INT(3),"
            + "stu_start_date DATE,"
            + "stu_end_date DATE,"
            + "stu_address CHAR(20),"
            + "stu_state CHAR(2),"
            + "stu_zip INT(5),"
            + "stu_area_code INT(3),"
            + "stu_phone INT(11),"
            + "payee_uid CHAR(11),"
            + "PRIMARY KEY(stu_uid)"
            + ")";
public String[] schoolofdbTables = {
        stmtCreateStudentTable,
        stmtCreateInstructorTable,
        stmtCreateAdminTable,
        stmtCreatePayeeTable,
        stmtCreateBookingTable,
        stmtCreateInstrAvailableTable,        
        stmtCreateInstrumentTable,
        stmtCreateLocationTable,        
        stmtCreatePaymentTable,
        stmtCreatePayRollTable,        
        stmtCreateUserTable,
        stmtCreateUserGroupTable,
        stmtCreateUserGroupMappingTable,};
public boolean createTables(Connection conn) {
        boolean bCreatedTables = false;
        for (int i = 0; i < schoolofdbTables.length; i++) {
            Statement stmt = null;
            temp = null;
            String temp = schoolofdbTables[i].trim();
            System.out.println("table: " + temp);
            try {
                stmt = (Statement) conn.createStatement();
                stmt.executeUpdate(temp);
                stmt.close();
                bCreatedTables = true;
            } catch (SQLException ex) {
                ex.printStackTrace();
            }
        }
        return bCreatedTables;
    }
run:
table: CREATE TABLE student (stu_uid CHAR(11),stu_password CHAR(11),stu_lname CHAR(20),stu_mname CHAR(20),stu_fname CHAR(20),stu_gender CHAR(1),stu_age INT(3),stu_start_date DATE,stu_end_date DATE,stu_address CHAR(20),stu_state CHAR(2),stu_zip INT(5),stu_area_code INT(3),stu_phone INT(11),payee_uid CHAR(11),PRIMARY KEY(stu_uid))
java.sql.SQLSyntaxErrorException: Syntax error: Encountered "(" at line 1, column 149.
        at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source)
        at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
        at org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown Source)

Recommended Answers

All 5 Replies

What's up with the INT(3) for the age column? If you explicitly plan on specifying the precision and scale, use the NUMERIC data type since INT doesn't support it or else just stick with INT (without the precision in brackets) which has a defined range. Read more about numeric data types in Derby here.

What's up with the INT(3) for the age column? If you explicitly plan on specifying the precision and scale, use the NUMERIC data type since INT doesn't support it or else just stick with INT (without the precision in brackets) which has a defined range. Read more about numeric data types in Derby here.

Thanks. It took a while to change syntax from MySQL db to the derby
sql. It seems Primary keys ,Int and varChar instead of char are a few of the differences.

I have a string in the class and all tables build now but I would like to
have that string in my properties. Is it possible?

it seems that those ' " ' quotations have to be there. Is this true?
I have been trying to use a String[] but I am thinking that it is pointing to a place in memory or something.
ex:

ModelUtils.getResource(" what ever str ");

prefered:

ModelUtils.getResource(schoolofdbTables[i].trim());

I will also need to transform that string to work in a properties sheet is this possible?
maybe loose the ' + ' 's and use \
can I use a List<list> ?
thanks

I'm not sure if I understand your question here but to get around the tedious act of escaping properties-file-sensitive-characters, consider writing your properties file in XML format. The entire code remains the same with the exception of the way you write down your properties. Not requiring the user to escape spaces, quotes, double quotes when configuring data in a properties file is a big win IMO.

Still trying to get the string to work in properties sheet. but I am reading the key as an element of the array. After 10 hrs of trial and error. I didn't rebuild the app so it could use the new properties

I'm not sure if I understand your question here but to get around the tedious act of escaping properties-file-sensitive-characters, consider writing your properties file in XML format. The entire code remains the same with the exception of the way you write down your properties. Not requiring the user to escape spaces, quotes, double quotes when configuring data in a properties file is a big win IMO.

I have not read the whole thing yet but it is what I want.

Can I use the exact same file but write it in XML format?
accessing properties is probably different too.

I will study that one.

thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.