Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. Here you will get the basic idea about how it will work.
  2. **JSP** page
  3.  
  4. <body>
  5. <head>
  6. <form action="servlet1" action="post">
  7. <input type="text" name="input1"/>
  8. </form>
  9. </head>
  10. </body>`
  11.  
  12.  
  13. Using the `input` tag, you can collect data from the user.
  14.  
  15. In **Servlet**,inside doPost method,
  16.  
  17. ` String input = request.getParameter("input1");
  18. DatabaseConnection connection = new DatabaseConnection();
  19. String query = "select * from tableName where columnName='"+input+"'";
  20. PreparedStatement ps = connection.prepareStatement(query);
  21. ResultSet rs = ps.executeQuery();
  22. if(rs.next()){
  23. String firstColVal = rs.getString("firstColName");
  24. }
  25. `
  26. This will collect data from each column *.
  27. For **database connection** create DatabaseConnection class,and write, to connect with database.
  28.  
  29. Connection connection=driverManager.getConnection("jdbc:mysql://localhost:portNumber/databaseName", "userName", "password");
  30.  
  31.  
  32.  
  33.  
  34.  
  35. In Netbeans, right click on project->select propeties->click libraries->add libraries->select import ->MYSQL JDBC Driver->click add library.
  36. Hope this sample will help you.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement