Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Here you will get the basic idea about how it will work.
- **JSP** page
- <body>
- <head>
- <form action="servlet1" action="post">
- <input type="text" name="input1"/>
- </form>
- </head>
- </body>`
- Using the `input` tag, you can collect data from the user.
- In **Servlet**,inside doPost method,
- ` String input = request.getParameter("input1");
- DatabaseConnection connection = new DatabaseConnection();
- String query = "select * from tableName where columnName='"+input+"'";
- PreparedStatement ps = connection.prepareStatement(query);
- ResultSet rs = ps.executeQuery();
- if(rs.next()){
- String firstColVal = rs.getString("firstColName");
- }
- `
- This will collect data from each column *.
- For **database connection** create DatabaseConnection class,and write, to connect with database.
- Connection connection=driverManager.getConnection("jdbc:mysql://localhost:portNumber/databaseName", "userName", "password");
- In Netbeans, right click on project->select propeties->click libraries->add libraries->select import ->MYSQL JDBC Driver->click add library.
- Hope this sample will help you.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement