1. Please take a little time for this simple survey! Thank you for participating!
    Dismiss Notice

JSP MySql Connectivity Problem

Discussion in 'Plesk for Linux - 8.x and Older' started by buntyindia, Dec 20, 2005.

  1. buntyindia

    buntyindia Guest

    0
     
    I Am getting Socket error while using this code whereas this code is working fine on my localTomcat Server.


    Code:
    <%@ page import = "java.io.*, java.util.*,java.net.URL,java.awt.*,java.lang.*,java.sql.*" %>
    <%@ page import="com.mysql.jdbc.Driver" %>
    
    <HTML>
    <head></head>
    <body>
    
    <%
    
        ResultSet rs;
    	Statement stmt;
         try {
    
              Class.forName("com.mysql.jdbc.Driver").newInstance();
    Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/petrofe","petro", "petro");
    
    
    	String sql = "SELECT * FROM sample";
    	stmt = conn.createStatement();
    	rs = stmt.executeQuery(sql);
    
    	while (rs.next())
    	{
    		out.println(rs.getString(1));
    		out.println(rs.getString(2));
    	}
    
                 // Do something with the Connection
    
    
             } catch (SQLException ex) {
                 // handle any errors
                 out.println("SQLException: " + ex.getMessage());
                 out.println("SQLState: " + ex.getSQLState());
                 out.println("VendorError: " + ex.getErrorCode());
             }
             catch (ClassNotFoundException cnfex)
    		 	   {
    		 	       out.println("SQLException: " + cnfex.getMessage());
    		 	   }
    %>
    
    
    
    </body>
    </html>
    
    ERROR


    Please Help

    Bunty
     
  2. tmonsen

    tmonsen Guest

    0
     
    I am not a java programmer at all, but it appears that your getting a permission error. I would begin by making certain that your user/pass for mysql are working. Type the following from the command line:

    mysql -u petro -p

    You should be prompted for your password, if you get a successfull connection: mysql>
    you will have at least narrowed the problem down to a tomcat/jdbc problem, and not a mysql problem.

    If that doesn't work, hopefully someone with more java experience would be able to help.
     
  3. billsutton

    billsutton Guest

    0
     
    In /var/tomcat4/conf/catalina.policy

    add the following to the web application grant section

    permission java.net.SocketPermission "localhost:3306", "connect,resolve";

    Bill
     
Loading...