我正在尝试创建一个下拉列表,如果用户在下拉列表中选择任一类型,该列表将在列表中显示特定数据。我一直在获取sql查询错误。这是我创建的代码:
Class.forName("xxx").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/xxxserverTimezone=Singapore", "xxx", "xxx");
String SQLQuery1 = ("SELECT Model,Brand,IMEI, YearManufactured, Country FROM initprinter where PID = " + Integer.parseInt(request.getParameter("test")));
PreparedStatement PS1 = con.prepareStatement(SQLQuery1);
ResultSet RS1 = PS1.executeQuery();
我试图在表中显示打印机的特定类型及其详细信息以供输出,但我得到的只是Http status 500错误和位于String查询语句的错误位置。
答案 0 :(得分:1)
您的query
应该如下所示:
String SQLQuery1 = "SELECT Model,Brand,IMEI, YearManufactured, Country FROM initprinter where PID = '"+ Integer.parseInt(request.getParameter("test")) +"'";
我也建议您使用Prepared statement
,如下所示:
PreparedStatement ps = con.prepareStatement("select Model,Brand,IMEI, YearManufactured, Country FROM initprinter where PID =?");
ps.setInt(1,Integer.parseInt(request.getParameter("test")));//setting parameter for ID=?
ResultSet resultset= ps.executeQuery();
希望这会有所帮助!