I have an issue using jdbc and a DB in MySQL.
The problem is that I want to make a seach using the Last Name of a person stored in a MySQL DB, from a JSP
The problem is that I cannot determine which sentence to use for this purpose, that can help me to display the information of the person who match with the search criteria.
This is my actual Servlet.
Expand|Select|Wrap|Line Numbers
- import java.io.IOException;
- import java.io.PrintWriter;
- import java.sql.*;
- import javax.servlet.*;
- import javax.servlet.http.*;
- import java.net.*;
- public class Changer extends HttpServlet {
- public Changer() {
- super();
- }
- public void doGet(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- response.setContentType("text/html");
- PrintWriter out = response.getWriter();
- String name=request.getParameter("name");
- String last=request.getParameter("last");
- String country=request.getParameter("country");
- String profile=request.getParameter("profile");
- String company=request.getParameter("company");
- String platform=request.getParameter("platform");
- String URL="jdbc:mysql://localhost:3806/Base01";
- try
- {
- Class.forName("com.mysql.jdbc.Driver");
- }catch(Exception ex)
- {
- out.println("error!");
- }
- try
- {
- Connection con=DriverManager.getConnection(URL,"superou","kliojk126");
- Statement stmt=con.createStatement();
- ResultSet rst=null;
- try{
- String SQL= "SELECT * FROM 01thllo1 WHERE lastN =
- System.out.print(SQL);
- rst=stmt.executeQuery(SQL);
- out.println("<TABLE BORDER CELLSPACING=3 CELLPADDING=3>");
- while(rst.next()){
- out.println("<tr>");
- out.println("<td>"+rst.getString("name"));
- out.println("<td>"+rst.getString("last"));
- out.println("<td>"+rst.getString("country"));
- out.println("<td>"+rst.getString("profile"));
- out.println("<td>"+rst.getString("company"));
- out.println("<td>"+rst.getString("platform"));
- }//while
- }catch(SQLException seq)
- {
- System.err.println("SQLException " + seq.getMessage());
- }
- }catch(SQLException se){
- System.err.println("SQLException: " + se.getMessage());
- }
- out.println("</TABLE>");
- }
- }
Thank you very much for your attention and help.