我计划为我的应用程序创建一个数据库,该数据库自动从文本字段中获取名称。(在运行文本字段时不为空)。但我有语法错误。这个相同的代码在同一个项目的另一个 java 页面中运行。下面的代码接受创建任务。
public void FacltyNameTable(){
String fcltyName = fcltyUserNameTxt.getText();
try{
Class.forName("com.mysql.jdbc.Driver");
conn = (Connection) DriverManager.getConnection(DB_URL_table, USER, PASS);
stmt = (Statement) conn.createStatement();
String sql1 = "CREATE TABLE IF NOT EXISTS '"+fcltyName+"' " +
"(id INTEGER not NULL AUTO_INCREMENT, " +
" rollNo VARCHAR(255), " +
" studentName VARCHAR(255), " +
"CommunicationOral INTEGER, "+
"Communicationwritten INTEGER, "+
"Leadership INTEGER, "+
"AnalyticalAbilities INTEGER, "+
"Interpersonalskills INTEGER, "+
"DecisionMakingSkills INTEGER, "+
"SelfConfidence INTEGER, "+
"Creativity INTEGER, "+
"Punctualityregularity INTEGER, "+
"GeneralAwareness INTEGER, "+
"Commitment INTEGER, "+
"Hardwork INTEGER, "+
" PRIMARY KEY ( id ))";
stmt.executeUpdate(sql1);
String insert1="INSERT IGNORE INTO '"+fcltyName+"'(id,rollNo,studentName,CommunicationOral,Communicationwritten,Leadership,AnalyticalAbilities,Interpersonalskills,DecisionMakingSkills,SelfConfidence,Creativity,Punctualityregularity,GeneralAwareness,Commitment,HardWork)VALUES(1,'1','ABHIJITH V GEORGE ',0,0,0,0,0,0,0,0,0,0,0,0)";
stmt.executeUpdate(insert1);
}catch(SQLException se){
//Handle errors for JDBC
se.printStackTrace();
}catch(Exception e){
//Handle errors for Class.forName
e.printStackTrace();
}finally{
//finally block used to close resources
try{
if(stmt!=null)
conn.close();
}catch(SQLException se){
}// do nothing
try{
if(conn!=null)
conn.close();
}catch(SQLException se){
se.printStackTrace();
}//end finally try
}//end try
}
以下显示错误
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 ''' (id INTEGER not NULL AUTO_INCREMENT, rollNo VARCHAR(255), studentName VARCH' at line 1
当我将 'String sql1 = "CREATE TABLE IF NOT EXISTS"+fcltyName+"' " +........
更改String sql1 = "CREATE TABLE IF NOT EXISTS fcltyName " +.......
为完美工作时。我认为我的查询是错误的。我需要帮助