gpt4 book ai didi

java - SQL异常: java. sql.SQLException : Parameter index out of range (1 > number of parameters,这是0)

转载 作者:行者123 更新时间:2023-12-02 02:53:16 27 4
gpt4 key购买 nike

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());
}

最佳答案

您在列名称中使用 # 会产生问题...您应该从列名称中删除 # 标记,并将其更正到数据库中。

关于java - SQL异常: java. sql.SQLException : Parameter index out of range (1 > number of parameters,这是0),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43476912/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com