File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JDBC Connectivity problem

 
Russ Wright
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Russ Wright
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic