Guest User

Untitled

a guest
Aug 19th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. Connecting to mysql from eclipse
  2. protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  3. Connection con = null;
  4. try{
  5. Class.forName("com.mysql.jdbc.Driver").newInstance();
  6. con = DriverManager.getConnection("jdbc:mysql//localhost:3306/try", "root", "password");
  7. }catch(Exception e){
  8. e.printStackTrace();
  9. }
  10. if(request.getParameter("select1")!=null){
  11. PrintWriter out = response.getWriter();
  12. String select1 = (String) request.getParameter("select1");
  13. int no = Integer.parseInt(select1);
  14. String query = "SELECT * FROM try.try where id='"+no+"'";
  15. out.print("<option>---select one---</option>");
  16. try{
  17. Statement stmt = (Statement) con.createStatement();
  18. ResultSet rs = stmt.executeQuery(query);
  19. while(rs.next()){
  20. out.print("<option>"+rs.getString("output")+"</option>");
  21. }
  22. }catch(Exception e){
  23. e.printStackTrace();
  24. }
  25. }
  26.  
  27. }
  28.  
  29. jdbc:mysql://localhost:3306/try
  30. ^-- you missed the colon here
Add Comment
Please, Sign In to add comment