• The APS Catalog has been deprecated and removed from all Plesk Obsidian versions.
    Applications already installed from the APS Catalog will continue working. However, Plesk will no longer provide support for APS applications.
  • Please be aware: with the Plesk Obsidian 18.0.78 release, the support for the ngx_pagespeed.so module will be deprecated and removed from the sw-nginx package.

JSP MySql Connectivity Problem

B

buntyindia

Guest
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

SQLException: Communications link failure due to underlying exception: ** BEGIN NESTED EXCEPTION ** java.security.AccessControlException MESSAGE: access denied (java.net.SocketPermission localhost resolve) STACKTRACE: java.security.AccessControlException: access denied (java.net.SocketPermission localhost resolve) at java.security.AccessControlContext.checkPermission(AccessControlContext.java:269) at java.security.AccessController.checkPermission(AccessController.java:401) at java.lang.SecurityManager.checkPermission(SecurityManager.java:524) at java.lang.SecurityManager.checkConnect(SecurityManager.java:1023) at java.net.InetAddress.getAllByName0(InetAddress.java:1000) at java.net.InetAddress.getAllByName0(InetAddress.java:981) at java.net.InetAddress.getAllByName(InetAddress.java:975) at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:133) at com.mysql.jdbc.MysqlIO.(MysqlIO.java:281) at com.mysql.jdbc.Connection.createNewIO(Connection.java:1696) at com.mysql.jdbc.Connection.(Connection.java:408) at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:270) at java.sql.DriverManager.getConnection(DriverManager.java:512) at java.sql.DriverManager.getConnection(DriverManager.java:171) at org.apache.jsp.mysqldb2_jsp._jspService(mysqldb2_jsp.java:62) at org.apache.jasper.runtime.HttpJspBase.service(Unknown Source) at javax.servlet.http.HttpServlet.service(HttpServlet.java) at org.apache.jasper.servlet.JspServletWrapper.service(Unknown Source) at org.apache.jasper.servlet.JspServlet.serviceJspFile(Unknown Source) at org.apache.jasper.servlet.JspServlet.service(Unknown Source) at javax.servlet.http.HttpServlet.service(HttpServlet.java) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Unknown Source) at org.apache.catalina.core.ApplicationFilterChain.access$0(Unknown Source) at org.apache.catalina.core.ApplicationFilterChain$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at org.apache.catalina.core.ApplicationFilterChain.doFilter(Unknown Source) at org.apache.catalina.core.StandardWrapperValve.invoke(Unknown Source) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Unknown Source) at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source) at org.apache.catalina.core.ContainerBase.invoke(Unknown Source) at org.apache.catalina.core.StandardContextValve.invoke(Unknown Source) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Unknown Source) at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source) at org.apache.catalina.core.ContainerBase.invoke(Unknown Source) at org.apache.catalina.core.StandardContext.invoke(Unknown Source) at org.apache.catalina.core.StandardHostValve.invoke(Unknown Source) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Unknown Source) at org.apache.catalina.valves.ErrorDispatcherValve.invoke(Unknown Source) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Unknown Source) at org.apache.catalina.valves.ErrorReportValve.invoke(Unknown Source) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Unknown Source) at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source) at org.apache.catalina.core.ContainerBase.invoke(Unknown Source) at org.apache.catalina.core.StandardEngineValve.invoke(Unknown Source) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Unknown Source) at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source) at org.apache.catalina.core.ContainerBase.invoke(Unknown Source) at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:594) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:392) at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:565) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:619) at java.lang.Thread.run(Thread.java:534) ** END NESTED EXCEPTION ** SQLState: 08S01 VendorError: 0


Please Help

Bunty
 
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.
 
In /var/tomcat4/conf/catalina.policy

add the following to the web application grant section

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

Bill
 
Back
Top