从表格中读取数据时显示此错误参数索引超出范围(1>参数数量)
问题描述:
String get_date = check_in_date.getText();
String get_customer_no = customer_no.getText();
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rst = null;
try{
String driver ="com.mysql.jdbc.Driver";
String url ="jdbc:mysql://localhost:3306/hotel";
String userid ="root";
String password ="tushar11";
Class.forName(driver);
conn = DriverManager.getConnection(url,userid,password);
pstmt = conn.prepareStatement("select occupantdetails.customer_name,
hoteldetails.service_detail, hoteldetails.cab_no from
occupantdetails JOIN hoteldetails ON
occupantdetails.customer_no=hoteldetails.customer_no");
pstmt.setString(1, get_customer_no);
rst = pstmt.executeQuery();
while(rst.next()){
txt_customer_name.setText(rst.getString("customer_name"));
txt_room_no.setText(rst.getString("service_detail"));
txt_cab_no.setText(rst.getString("cab_no"));
}
}
我对此很陌生。当我提取细节时,它显示参数错误,我无法解决这个问题。我想我已经写了正确的查询,并可能在Java代码中出现错误。从表格中读取数据时显示此错误参数索引超出范围(1>参数数量)
答
+0
非常感谢解决方案。我对此很新。 –
您的查询没有任何参数。但你仍然通过一个。因此,无论是将参数添加到查询还是不添加参数。 –