2013-01-15 47 views
-1

我在我的try子句中有這個...它工作正常,如果我刪除pst.setString(5, value5), 它也可以工作,如果我刪除所有的整數值,但我不能讓它工作如果添加所有的整數和值5 ...在準備好的語句中的整數和字符串

try { 
    Class.forName("org.postgresql.Driver"); 
    connection = DriverManager.getConnection(connectionURL, "username", "password"); 
    String sql ="UPDATE table1 SET value1 = ?, value2 = ?, value3 = ?, value4 = ? value5 = ? WHERE value6 = ? "; 
    PreparedStatement pst = connection.prepareStatement(sql); 

    Integer value1A = Integer.parseInt(value1), 
    value2A = Integer.parseInt(value2), 
    value2A = Integer.parseInt(value3), 
    value2A = Integer.parseInt(value4); 

    pst.setInt(1, value1A); 
    pst.setInt(2, value2A); 
    pst.setInt(3, value3A); 
    pst.setInt(4, value4A); 
    pst.setString(5, value5); 
    pst.setString(6, value6); 

    int numRowsChanged = pst.executeUpdate(); 

    pst.close(); 
} 
+1

另請發表您的異常。 – jlordo

回答

5

你錯過了你的SQL逗號:

String sql ="UPDATE table1 SET value1 = ?, value2 = ?, value3 = ?, value4 = ?, value5 = ? WHERE value6 = ? "; 
                      ^
1

似乎你缺少一個逗號?