2015-10-15 83 views
0
try { 
    Class.forName("com.mysql.jdbc.Driver"); 
    Connection dbaTo = DriverManager.getConnection("jdbc:mysql://localhost:3306/ourDB1", "root", ""); 

    PreparedStatement stat2 = dbaTo.prepareStatement("SELECT * FROM tblEntry"); 
    journEnt = journCombo.getSelectedItem().toString(); 

    String sqlbebe = "INSERT INTO tblJournEnt(strEntJournCode, strEntJournType) VALUES (?, ?)"; 
    PreparedStatement stat3 = dbaTo.prepareStatement(sqlbebe); 
    ResultSet resultaNgSet = stat2.executeQuery(); 

    if(resultaNgSet.next()) { 
    do{ 
     kuhaEntCode = resultaNgSet.getString(1);  
     substring2 = kuhaEntCode.substring(Math.max(kuhaEntCode.length() - 3, 0)); 

    }while(resultaNgSet.next()); 
     } //IF//////////////////////////////////////////////////////////// 

    else{ 
     stringsaEnt = "Ent000";   
    } 

    int convertToInt2 = Integer.parseInt(substring2); 
    int addition2 = convertToInt2 + 1; 

    if (addition2 >= 10) { 
     String prd = "ent0"; 
     stringsaEnt = prd + addition2; 
    } 
    else { 
     String prd2 = "ent00"; 
     stringsaEnt = prd2 + addition2; 
     //pasaEnt(stringsaEnt); 

    } 



    stat3.setString(1, stringsaEnt); 
    stat3.setString(2, journEnt); 
    stat3.addBatch(); 
    stat3.executeBatch(); 
    stat3.close(); 

}catch(Exception saiko) { 

} 

这是我的代码,我不知道,但它不会插入到我的数据库插入到MySQL不工作

+0

永远永远永远永远永远永远永远永远永远永远永远永远永远永远永远永远永远永远总是关闭你的'连接'在'finally'块 –

回答

0

你不是stat3/sqlbebe提供两个参数。

此外,将它全部封装在带空catch的try块中并没有帮助,这会导致任何异常被默默忽略。打印/记录/重新抛出错误,你会看到为什么你的SQL语句失败。