I have a simple project where at the end of user registration it gets to create a specific table by the name of that user in mySql Database.
After connecting to DB. Function for ExecutingUpdate:
public String UpdateDBQuery(String query) throws IOException{
try {
int ursa = st.executeUpdate(query);
if (ursa == 0) {
throw new SQLException("Creating user failed, no rows affected.");
} else {
return "succeed";
}
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
Calling function:
String DBOutput = connect.UpdateDBQuery("CREATE TABLE '"+UserName+"' (ID INT(20) AUTO_INCREMENT PRIMARY KEY, PROFILEIMAGES VARCHAR(100), REG_DATE timestamp)");
But my code above through an exception saying:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''jasdfhkjhasdkfj' (ID INT(20) AUTO_INCREMENT PRIMARY KEY, PROFILEIMAGES VARCHAR(' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:404)
at com.mysql.jdbc.Util.getInstance(Util.java:387)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:942)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3966)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3902)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2526)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2673)
Although I searched through internet but couldn't find the problem.
all replies are much appreciate:)