Win a copy of Spark in Action this week in the Open Source Projects forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

JDBC Connectivity problem

 
Greenhorn
Posts: 7
  • 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)
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • 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
  • 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
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • 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".
 
permaculture is a more symbiotic relationship with nature so I can be even lazier. Read tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic