2013-08-12 2 views
-1

나는 (null가 아닌 실행 텍스트 필드에서). 자동으로 텍스트 필드에서 이름을 따 내 응용 프로그램에 대한 데이터베이스를 만들 계획을 가지고 나누었다 내가 같은 다른 자바 페이지에서 동일한 코드 실행을 구문 error.This이 다음 코드는 생성 작업을 수행합니다. 다음데이터베이스 생성

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 

내가 변경 '문자열 SQL1을 보여줍니다 = "NOT이있는 경우 테이블 만들기 "+fcltyName+"' " +........는 완벽하게 내 쿼리 Wromg.I 도움이 필요

하시기 바랍니다 생각을 남기고 String sql1 = "CREATE TABLE IF NOT EXISTS fcltyName " +.......
+2

이 너무 많은 이유가 여기에 세부 사항으로 이동하기위한 정말 좋은 생각입니다! –

답변

0

나는 연결 CONN = DriverManager에 .... 등 는 타입 캐스팅을 사용 해달라고을 사용합니다. 또한 항상 준비된 문을 사용합니다. 그것은 단정하고 안전합니다.

작은 오류가 하나 있습니다. 예 : 아이디 INT (10)는 NOT NULL AUTO_INCREMENT INT의

크기를 지정해야 사용되어야한다. mysql을 가정 할 때

2

다음과 같이이 행을 변경하면 도움이됩니까? (제거 따옴표)

 String sql1 = "CREATE TABLE IF NOT EXISTS "+fcltyName+" " + 
+0

작은 따옴표를 제거하면 같은 오류가 나타납니다 –

+0

좁히려 고 시도하십시오 - Java가없는 SQL을 사용해보십시오. 문제가 있으면 열 절반을 시도한 다음 다른 절반을 시도하면 곧 문제가 발생합니다. UR 답변 감사합니다 .... 좀 도와 내가 아무 소용이 – necromancer

+0

@DeepuKrishna .... OP 대신에 – necromancer

1

귀하의 fcltyUserNameTxt 아마 비어 있습니다. 당신은 로깅을 시도 할 수

String fcltyName = fcltyUserNameTxt.getText(); 
System.out.println(fcltyName); // ?? 
+1

거의 다! 2 더 upvotes :) – necromancer