Note that there are some explanatory texts on larger screens.

plurals
  1. PODatabase creation
    text
    copied!<p>I have plan to create a database for my application which takes the name from a text field automatically.(at run textfield not null).But i have syntax error.This same code run in another java page in the same project.The following code takes the creation task.</p> <pre><code> 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 } </code></pre> <p>Following shows the error</p> <pre><code> 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 </code></pre> <p>When i change 'String sql1 = "CREATE TABLE IF NOT EXISTS <code>"+fcltyName+"' " +........</code> to <code>String sql1 = "CREATE TABLE IF NOT EXISTS fcltyName " +.......</code> its perfectly works.I think my query is Wromg.I need help please </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload