Newsgroup: it.comp.java
Titolo: jdbc, servlet, mysql problema di connessione db

Salve,
ho un problema con mysql,servlet,jdbc...
Uso tomcat come servlet engine e sto facendo un'applicazione web, tempo fa
ne ho fatta qualcuna di prova con postgresql ma il provider che ospiterà il
mio sito usa mysql. Tutto bene finchè non tento di connettermi con le jdbc.
Ovviamente ho messo il driver dal sito mysql 3.0.16 connector/J nella
directory /lib del /context, il CLASSPATH è settato correttamente come
JAVA_HOME
Ho fatto una prova con una classe semplicissima che tenta di connettersi
ecco l'esempio:
ublic class Query extends HttpServlet {
    public void doGet(HttpServletRequest request,
                      HttpServletResponse response) 
        throws IOException, ServletException {
        PrintWriter out = response.getWriter();
 String sql;
 Connection con = null;
 PreparedStatement pstmt;
 ResultSet rs;
 String url = "jdbc:mysql://
127.0.0.1/dbdiprova
"; // ho provato anche a
mettere localhost
 String user = "NOMEUSER";
 String passwd = "PASSWORDCORRETTA";
 try {
            Class.forName("com.mysql.jdbc.Driver").newInstance();
 } catch (ClassNotFoundException cnfe) {
            log("Driver jdbc non trovato: " + cnfe.getMessage());
 }
 try {
            con = DriverManager.getConnection(url, user, passwd);
 } catch (SQLException sqle) {
            //Se si verifica un errore, lo registro nei log di Tomcat e 
            //stampo un avviso nel documento html!!!
            log("drivermanager non trovato: "+sqle.getMessage());
            out.println("<p>Errore nella connessione al database:
"+sqle.getMessage()+"</p>");
 }
}
Il problema è che lancia la seguente eccezzione:
Unable to connect to any hosts due to exception:
java.security.AccessControlException: access denied
(java.net.SocketPermission 
127.0.0.1:3306
 connect,resolve) ** BEGIN NESTED
EXCEPTION ** java.security.AccessControlException MESSAGE: access denied
(java.net.SocketPermission 
127.0.0.1:3306
 connect,resolve) STACKTRACE:
java.security.AccessControlException: access denied
(java.net.SocketPermission 
127.0.0.1:3306
 connect,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:1026) at
java.net.Socket.connect(Socket.java:446) at
java.net.Socket.connect(Socket.java:402) at java.net.Socket
(Socket.java:309) at java.net.Socket.(Socket.java:124) at
com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:124)
at com.mysql.jdbc.MysqlIO.(MysqlIO.java:225) at
com.mysql.jdbc.Connection.createNewIO(Connection.java:1783) at
com.mysql.jdbc.Connection.(Connection.java:450) at
com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:411)
at java.sql.DriverManager.getConnection(DriverManager.java:512) at
java.sql.DriverManager.getConnection(DriverManager.java:171) at
Query.doGet(Query.java:59) at
javax.servlet.http.HttpServlet.service(HttpServlet.java:740) at
javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at
org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServlet.java:466)
at
org.apache.catalina.servlets.InvokerServlet.doGet(InvokerServlet.java:180)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740) at
javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.access$00
(ApplicationFilterChain.java:98) at
org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:176)
at java.security.AccessController.doPrivileged(Native Method) at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:172)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995) at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995) at
org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2422)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at
org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:163)
at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995) at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995) at
org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:199) at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:828)
at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:700)
at
org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:584)
at
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:534) ** END NESTED EXCEPTION ** 
Vi prego datemi dei consigli...

prova così
public void apriConnessione() {
	try {
		Class.forName("com.mysql.jdbc.Driver");
	String url = "jdbc:mysql://localhost:3306/tuodb?user=root&password=";
 
		conn = DriverManager.getConnection (url);
		stmt = conn.createStatement();
		  }
		catch (SQLException e) {
			e.printStackTrace();
		} 
	catch (ClassNotFoundException ex) {
			 ex.printStackTrace();
		}
	}