jsp search query

Solutions on MaxInterview for jsp search query by the best coders in the world

showing results for - "jsp search query"
Angelo
17 Nov 2018
1
2<%@page import="java.sql.DriverManager"%>
3
4<%@page import="java.sql.ResultSet"%>
5
6<%@page import="java.sql.Statement"%>
7
8<%@page import="java.sql.Connection"%>
9
10<%
11
12String id = request.getParameter("userid");
13
14String driver = "com.mysql.jdbc.Driver";
15
16String connectionUrl = "jdbc:mysql://localhost:3306/";
17
18String database = "test";
19
20String userid = "root";
21
22String password = "";
23
24try {
25
26Class.forName(driver);
27
28} catch (ClassNotFoundException e) {
29
30e.printStackTrace();
31
32}
33
34Connection connection = null;
35
36Statement statement = null;
37
38ResultSet resultSet = null;
39
40%>
41
42<!DOCTYPE html>
43
44<html>
45
46<body>
47
48
49
50<h1>Retrieve data from database in jsp</h1>
51
52<table border="1">
53
54<tr>
55
56<td>first name</td>
57
58<td>last name</td>
59
60<td>City name</td>
61
62<td>Email</td>
63
64
65
66</tr>
67
68<%
69
70try{
71
72connection = DriverManager.getConnection(connectionUrl+database, userid, password);
73
74statement=connection.createStatement();
75
76String sql ="select * from users";
77
78resultSet = statement.executeQuery(sql);
79
80while(resultSet.next()){
81
82%>
83
84<tr>
85
86<td><%=resultSet.getString("first_name") %></td>
87
88<td><%=resultSet.getString("last_name") %></td>
89
90<td><%=resultSet.getString("city_name") %></td>
91
92<td><%=resultSet.getString("email") %></td>
93
94
95</tr>
96
97<%
98
99}
100
101connection.close();
102
103} catch (Exception e) {
104
105e.printStackTrace();
106
107}
108
109%>
110
111</table>
112 
113
114</body>
115
116</html>
117
118
similar questions
queries leading to this page
jsp search query