-
Notifications
You must be signed in to change notification settings - Fork 43
/
RetriveData.java
39 lines (38 loc) · 1.08 KB
/
RetriveData.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.sql.*;
import java.util.*;
import javax.servlet.ServletConfig;
public class RetriveData extends HttpServlet {
public void init(ServletConfig c){
}
public void doGet(HttpServletRequest rq,HttpServletResponse re) throws ServletException{
re.setContentType("text/html");
Connection c=null;
PreparedStatement s=null;
ResultSet rs=null;
try{
PrintWriter out=re.getWriter();
Class.forName("com.mysql.jdbc.Driver");
c=DriverManager.getConnection("jdbc:mysql://localhost:3306/mydb","root","onishi1313");
String query="select * from emp_info";
s=c.prepareStatement(query);
out.println("<h1>Information Of Employee</h1>");
out.println("<h2>enoll=130050131044</h2><br/>");
rs=s.executeQuery();
while(rs.next()){
out.println("<br/><h3>id:"+rs.getString("id")+"</h3>");
out.println("<h3>name:"+rs.getString("name")+"</h3>");
}
}
catch(IOException i){
System.out.println("IOException");
}
catch(Exception e){
System.out.println(e);
}
}
public void destroy(){
}
}