Reputation: 125
Now I use postgreSQL and make stockmanagement program.
While I make table, the error has occured.
My Code like this!
import java.sql.Connection;
import java.sql.Statement;
public class Create_Table {
public static void main(String[] args) {
Connection connection = null;
Statement statement = null;
ConnectDB obj_ConnectDB = new ConnectDB();
connection = obj_ConnectDB.get_connection();
try {
String query = "CREATE TABLE IF NOT EXISTS stockmanagement ("
+ "ID SERIAL primary key, "
+ "Name varchar(20), "
+ "Unit_price numeric(15,1), "
+ "Qty INT(20),"
+ "Imported_Date Date,"
+ ")";
statement = connection.createStatement();
statement.executeUpdate(query);
System.out.println("finished");
} catch (Exception e) {
e.printStackTrace();
}
}
}
And the contents of error are as follows.
error : syntax error, "("
How can I fix this error?
If you know this solution, can you teach me?
Upvotes: 0
Views: 43
Reputation: 1781
You have two errors in the string.
This should work
String query = "CREATE TABLE IF NOT EXISTS stockmanagement ("
+ "ID SERIAL primary key, "
+ "Name varchar(20), "
+ "Unit_price numeric(15,1), "
+ "Qty INT,"
+ "Imported_Date Date"
+ ")";
Upvotes: 2