1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

The driver has not received any packets from the server

Discussion in 'JSP' started by IamNew, Jul 26, 2012.

  1. IamNew

    IamNew New Member

    Joined:
    Nov 29, 2011
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Hi experts,

    I am currently doing an web application which required data to be retrieved from the MySQL database. I am currently using eclipse EE to write my
    JSP scripts. But there is something wrong with the server connection.

    Here's my code
    Code:
    <%@ page language="java" 
    import = "java.io.*"
    import="java.sql.*" 
    import = "javax.sql.*"
    import = "java.sql.Connection"
    import = "java.sql.Statement"
    import = "java.sql.ResultSet"
    import = "java.sql.DriverManager"
    %>
    <%
    response.setContentType("text/html");
    String licenseeName=request.getParameter("licenseeName");
    String businessName=request.getParameter("businessName");
    String licenseNo=request.getParameter("licenseName");
    %>
    <h2><font color=blue>
    <%
    
        Connection connection=null;
        ResultSet rs=null;
        String licenseeNam=new String("");
        String businessNam=new String("");
        String licenseN=new String("");
        String licenseeInfo=new String ("");
      	String name=new String("");
      	String strQuery=new String("");
        response.setContentType("text/html");
        try {
           // Load the database driver
          Class.forName("com.mysql.jdbc.Driver");
          // Get a Connection to the database
          connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root"); 
          //Add the data into the database
      strQuery = "select * from nam";
      Statement s = connection.createStatement();
      s.executeQuery (strQuery);
       rs = s.getResultSet();
      while (rs.next ()){
    	licenseeNam=rs.getString("licenseeName");
    	businessNam=rs.getString("businessName");
    	licenseN=rs.getString("licenseNo");
        licenseeInfo = rs.getString("licenseeName")+"& "+rs.getString("businessName")+"& " +  rs.getString("licenseNo") ;
        if(licenseeNam.equals(licenseeName)&&businessNam.equals(businessName)&&licenseN.equals(licenseNo)){
            name=licenseeNam;
          }
           }
        rs.close ();
          s.close ();
          }catch(Exception e){
          System.out.println("Exception is ;"+e);
          }
          if(name.equals(licenseeName))
        {
      %>
      <font color="red">Welcome</font>
      <%
          out.println(name);
          out.println(licenseeInfo);
       }
        else{
        out.println("You are not an authentic licensee!"); 
          }
    %>
    </font></h2>
    
    The system is always printing the " You are not an authentic licensee" even I am submitting the right details to be database. The console printing the message of "The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server. Exception is ;com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure"
    Please advise. Thanks in advance
     

Share This Page