try {
Class.forName("com.mysql.jdbc.Driver");
String connectionUrl = "jdbc:mysql://Localhost/basic_credit? autoReconnect=true&useSSL=false" ;
Connection con = DriverManager.getConnection(connectionUrl,"root","superchan009");
String sql="INSERT INTO new_table(date, time, customer_name, address, contact#1, contact#2, item_name, final_price, downpayment, remaining_balance, length_ofinstallment, payment_permonth, first_due, last_due)VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
PreparedStatement ps=con.prepareStatement(sql);
ps.setString(1,jLabel16.getText());
ps.setString(2,jLabel17.getText());
ps.setString(3,tf1.getText());
ps.setString(4,tf2.getText());
ps.setString(5,tf3.getText());
ps.setString(6,tf4.getText());
ps.setString(7,tf6.getText());
ps.setString(8,tf7.getText());
ps.setString(9,tf8.getText());
ps.setString(10,tf9.getText());
ps.setString(11,tf10.getText());
ps.setString(12,tf11.getText());
ps.setString(13,tf12.getText());
ps.setString(14,tf13.getText());
ps.executeUpdate();
JOptionPane.showMessageDialog(null,"DATA SAVED! THANK YOU!");
} catch (SQLException e) {
System.out.println("SQL Exception: "+ e.toString());
} catch (ClassNotFoundException cE) {
System.out.println("Class Not Found Exception: "+ cE.toString());
}
0
A
回答
2
您在列名中使用#
創造問題......你應該從刪除#
標籤列名稱並將其更正到數據庫中。
0
try {
Class.forName("com.mysql.jdbc.Driver");
String connectionUrl = "jdbc:mysql://Localhost/basic_credit? autoReconnect=true&useSSL=false" ;
Connection con = DriverManager.getConnection(connectionUrl,"root","superchan009");
String sql="INSERT INTO new_table(date, time, client_name, address, contact1, contact2, item_name, final_price, downpayment, remaining_balance, length_ofinstallment, payment_permonth, first_due, last_due) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
PreparedStatement ps=con.prepareStatement(sql);
ps.setString(1,jLabel16.getText());
ps.setString(2,jLabel17.getText());
ps.setString(3,tf1.getText());
ps.setString(4,tf2.getText());
ps.setString(5,tf3.getText());
ps.setString(6,tf4.getText());
ps.setString(7,tf6.getText());
ps.setString(8,tf7.getText());
ps.setString(9,tf8.getText());
ps.setString(10,tf9.getText());
ps.setString(11,tf10.getText());
ps.setString(12,tf11.getText());
ps.setString(13,tf12.getText());
ps.setString(14,tf13.getText());
ps.executeUpdate();
JOptionPane.showMessageDialog(null,"DATA SAVED! THANK YOU!");
} catch (SQLException e) {
System.out.println("SQL Exception: "+ e.toString());
} catch (ClassNotFoundException cE) {
System.out.println("Class Not Found Exception: "+ cE.toString());
}
如果您打算爲列名使用特殊字符「#」,則SQL與JAVA連接區分大小寫。
+1
這是打算作爲答案嗎?如果沒有,請**編輯**您的問題;如果是答案,請添加解釋,而不僅僅是代碼。 –
相關問題
- 1. 值java.sql.SQLException:參數指標超出範圍
- 2. 異常值java.sql.SQLException:參數索引超出範圍(1>參數的數量,這是0)
- 3. SQL異常:參數指標超出範圍
- 4. java.sql.SQLException:參數索引超出範圍(1>參數數量,爲0)。
- 5. error java.sql.SQLException:參數索引超出範圍(1>參數數量,即0
- 6. java.sql.SQLException:參數索引超出範圍(1>參數數量,爲0)ERROR
- 7. java.sql.SQLException:參數索引超出範圍(1>參數數量,爲0)
- 8. java.sql.SQLException中的參數指標超出範圍
- 9. java.sql.SQLException中:參數索引超出範圍(2>的參數號,它是0)
- 10. java.sql.SQLException中:參數索引超出範圍(1>參數的數量,這是0).NOT獲得如何解決
- 11. 參數超出範圍異常
- 12. ListView異常:System.ArgumentOutOfRangeException:參數超出範圍
- 13. MyBatis的參數指標超出範圍
- 14. 參數索引超出範圍(1>參數數量,即0)
- 15. 參數索引超出範圍(2>參數數量,即0)
- 16. 異常「參數索引超出範圍(1>參數數目,爲0)」。
- 17. java sql SQLException:參數索引超出範圍(1>參數數量,爲0)
- 18. 子串 - 參數超出範圍異常 - startIndex參數
- 19. 指數0超出範圍
- 20. 錯誤java.sql.SQLEception:參數索引超出範圍(1>參數數量,它是0)
- 21. 指數超出範圍的異常 - C#
- 22. 指數超出範圍的異常
- 23. 參數'0'超出範圍錯誤
- 24. 休眠:參數索引超出範圍(8>參數的數量,這是7)
- 25. Java參數索引超出範圍(2>參數的數量,這是1)
- 26. 參數索引超出範圍(8>參數的數量,這是7)
- 27. 嵌套的異常是java.sql.SQLException中:無效的參數指標1
- 28. 指數超出範圍異常錯誤
- 29. SQL異常參數索引超出範圍
- 30. 錯誤顯示java.sql.SQLException:參數索引超出範圍(1>參數數量,爲0)
「VALUES」前缺少空格。 – Berger
請幫我這個。我已經省略了「?」中的引號但是,它不起作用。怎麼了? –
'contact#1'不可能是一個沒有被轉義的有效名字,你使用了哪個數據庫? –