aspose file tools*
The moose likes JDBC and the fly likes JDBC Connectivity problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "JDBC Connectivity problem" Watch "JDBC Connectivity problem" New topic
Author

JDBC Connectivity problem

Russ Wright
Greenhorn

Joined: Dec 20, 2003
Posts: 7
Hi All!
I'm having some problems with a java app I'm writing for school. I have mysql running on my local box and the database and table exist. The user has insert update select delete rights. I have the mysql connectj driver installed.
MY CODE:
try
{
//using MySQL database connectj driver
//www.mysql.com
//syntax example:
//String cs = "jdbc:mysql://"+dbserver+"/"+dbname+"?user="+user
+"&password="+password;
url = "jdbc:mysql://127.0.0.1:3306/TS5502?user=java&password=secret";
//register the MySQL Driver
Class.forName("com.mysql.jdbc.Driver").newInstance();
connect = DriverManager.getConnection(url);
connectField.setText("Connection successful");
}
catch(ClassNotFoundException cnfx)
{
cnfx.printStackTrace();
connectField.setText("Connection unsuccessful" + cnfx.toString());
}
catch (SQLException sqlx)
{
sqlx.printStackTrace();
connectField.setText("Connection unsuccessful" + sqlx.toString());
}
catch (Exception ex)
{
ex.printStackTrace();
connectField.setText("Connection unsuccessful" + ex.toString());
}

THE ERROR:
java.sql.SQLException: Unable to connect to any hosts due to exception:
java.security.AccessControlException: access denied
(java.net.SocketPermission 127.0.0.1:3306 connect,resolve)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:1797)
at com.mysql.jdbc.Connection.<init>(Connection.java:562)
at
com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:361)
at java.sql.DriverManager.getConnection(DriverManager.java:512)
at java.sql.DriverManager.getConnection(DriverManager.java:193)
at finalProject.AddressBook.myInit(AddressBook.java:398)
at finalProject.AddressBook.init(AddressBook.java:85)
at sun.applet.AppletPanel.run(AppletPanel.java:353)
at java.lang.Thread.run(Thread.java:534)
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Welcome to Javaranch Russ!
First, I must ask you to change your Display Name to conform to our Naming Policy. Obviously ficticious names are not allowed.
Secondly, I ran your code against my own database and it worked just fine. I noticed part of your exception included an applet exception. Are you running this from an applet? If so, we have different problems. Applet exist in a security sandbox and by default don't have access to open sockets on a PC. Now typically, you don't have a problem when everything is on a single PC like you stated, but I am thinking that this is the problem.


GenRocket - Experts at Building Test Data
Russ Wright
Greenhorn

Joined: Dec 20, 2003
Posts: 7
Thanks for the welcome!
Yes I was running this as an applet. I didn't even realize Ihad set this up as an applet. Now it works just fine.
Regards
Russ
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Originally posted by Russ Wright:
Thanks for the welcome!
Yes I was running this as an applet. I didn't even realize Ihad set this up as an applet. Now it works just fine.
Regards
Russ

Good deal Russ. And thanks for the name change! Hope to see you "round the Ranch".
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JDBC Connectivity problem