Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.servlet.http.*;
- import javax.servlet.*;
- import java.io.*;
- import java.sql.*;
- public class abc extends HttpServlet{
- public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException{
- res.setContentType("text/html");
- PrintWriter pw = res.getWriter();
- String id_passed = req.getParameter("id");
- String pass = req.getParameter("password");
- //JDBC code goes here
- try{
- pw.println("<html><body>");
- pw.println("hello world");
- Class.forName("com.mysql.jdbc.Driver");
- Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/java","root","toor");
- Statement stmt = con.createStatement();
- ResultSet rs = stmt.executeQuery("SELECT * FROM admin");
- while(rs.next()){
- int id_fetched = rs.getInt("id");
- String name = rs.getString("name");
- pw.println("Welcome "+name);
- pw.println("</body></html>");
- pw.close();
- }
- System.out.println("Connection sucessfull");
- }catch(SQLException i){
- i.printStackTrace();
- }catch(Exception e){
- e.printStackTrace();
- }
- //JDBC code ends here
- }
- }
Add Comment
Please, Sign In to add comment