permaculture playing cards*
The moose likes Servlets and the fly likes new to servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "new to servlet" Watch "new to servlet" New topic
Author

new to servlet

Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
hi all, first time servelt and it's going ok.
I just have this minor problem when trying to connect the db:

my code:


the result is:

Hello, Brave new World 3 5423!
the value of getHost is: localhost
err 2:com.mysql.jdbc.Driver
done!

can someone guide me why the conn fails?
I added the mysql jar file to the project (using eclipse)

thanks
peter
Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
ok i semi fixed the problem. I pleaced the jar in the lib section.
now, i get an sqlexception:

Hello, Brave new World 20xbx!
Hello, Brave 22
err 1:
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(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkConnect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:124)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:225)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:1783)
at com.mysql.jdbc.Connection.<init>(Connection.java:450)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:411)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at HelloServlet.doGet(HelloServlet.java:23)
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$000(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:2417)
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:172)
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:193)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:781)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:549)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:589)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:666)
at java.lang.Thread.run(Unknown Source)


** END NESTED EXCEPTION **


done!

anyone?
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Are both, server and DB, on the same machine? I dont think so.
Some security issue contact to system administrator.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

java.security.AccessControlException
MESSAGE: access denied (java.net.SocketPermission 127.0.0.1:3306 connect,resolve)


That's not a SQL exception.
It's a socket/permissions error.

As Adeel said, look into the security on that box or with your network.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
>>Are both, server and DB, on the same machine? I dont think so.

The server and db are on the same machine.


>>It's a socket/permissions error.
what do you mean, and what can i do?

thanks for your input.
Peter
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
Make sure mySQL is up and running.


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
it is, of course
Jeffrey Hunter
Ranch Hand

Joined: Apr 16, 2004
Posts: 305
Check your firewall, and if it is on, you may need to open up a hole so JDBC can access the db.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

I don't think this is an operating system issue or a network issue. The message is something to do with Java security, it's coming from the Java security manager that's configured into your Tomcat instance.

I had the same thing in Websphere when I tried to use RMI (not JDBC, but it was the same complaint, connecting to a socket). I solved that one by configuring it to turn on (not off, on!) Java 2 security and providing a security policy file. But other people don't seem to have a problem in using JDBC in Tomcat so surely there's a simpler way to fix your configuration. I haven't used Tomcat so I couldn't guess how to do it.
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Have you tried to connect with some other DB?

Or you can go to mySQL forum. It might be the driver problem. Because Tomcat comes with nothing like this. Have you made any change in Tomcat configuration?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: new to servlet
 
Similar Threads
Query about Connection interface
send variable value from one servlet to another servlet for itext pdf
LoginBean doesn't compile
Problem in connecting MySql with Servlets
Configuring JNDI for JavaBean in Tomcat 5