I have been trying to select type of printer on the "first" try catch method to output the "second" try catch method but it does not showing the result at all even i have selected the "first" printer selection.
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import = "java.sql.*"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/xxx?serverTimezone=Singapore","xxx", "xxx");
String SQLQuery = "SELECT * FROM testprinter";
Statement STM = conn.createStatement();
ResultSet RS = STM.executeQuery(SQLQuery);
%>
<P>Printer:
<select name = "testprinter1" id = "testprinter1" onchange="this.form.submit();">
<option value = "0">Select Printer</option>
<% while(RS.next()){ %>
<option value = "<%=RS.getInt("PID")%>"
<%
if(request.getParameter("testprinter1") != null){
if(RS.getInt("PID") == Integer.parseInt(request.getParameter("testprinter1"))){
out.print("selected");
}
}
%>
>
<%=RS.getString("Brand")%>
</option>
<% }
} catch (Exception e1) {
e1.printStackTrace();
}
%>
</select>
</P>
<table class = "table table-bordered table-striped">
<tr>
<th>A</th>
<th>B</th>
<th>C</th>
<th>D</th>
<th>E</th>
</tr>
<%
try{
String Query = "SELECT a, b, c, d, e FROM testprinter2 WHERE PID = ?";
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/xxx?serverTimezone=Singapore","xxx", "xxx");
PreparedStatement PS = con.prepareStatement(Query);
PS.setString(1, request.getParameter("testprinter1"));
ResultSet rs = PS.executeQuery();
while(rs.next()){
%>
<tr>
<td><%= rs.getString("a")%></td>
<td><%= rs.getString("b") %></td>
<td><%= rs.getString("c") %></td>
<td><%= rs.getString("d") %></td>
<td><%= rs.getString("e") %></td>
<tr>
<%
}
} catch (Exception e2) {
e2.printStackTrace();
}
%>
</body>
</html>
Expected Output of the result:
Printer : "user select the printer"
Table:
A | B | C | D | E
a | b | c | d | e
Actual result :
Printer : "user select the printer"
table : "empty blank"