By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,417 Members | 1,819 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,417 IT Pros & Developers. It's quick & easy.

Java applet jdbc error [MySQL DB]

P: 3
Hello,

I'm stuck with the same problem for a few days already. In my applet, in which users can login to see their account details, I want to connect to my databases which is located at localhost. This is perfectly possible in an application but nearly impossible in an applet. If some of you guys figured this out before please help me. benieth you will find the code I've used:

users_db is the database i use and 3306 is the default localhost port as far as i remember :D

Expand|Select|Wrap|Line Numbers
  1. static String DBURL = "jdbc:mysql://localhost:3306/users_db?user=****&password=********";
  2. try {
  3.  
  4.                 try {
  5.                 try {
  6.                     try {
  7.                         Class.forName("com.mysql.jdbc.Driver").newInstance();
  8.                     } catch (InstantiationException ex) {
  9.  
  10.                     } catch (IllegalAccessException ex) {
  11.  
  12.                     }
  13.                 } catch (ClassNotFoundException ex) {
  14.  
  15.                 }
  16.                 } 
  17.                 catch (Exception ex) {
  18.  
  19.                 }
  20.  
  21.  
  22.  
  23.       Connection con = DriverManager.getConnection(DBURL);
  24.       System.out.println("Succesfully connected!");
  25.       Label ok = new Label("Connected");
  26.       add(ok);
  27.     }
  28.     catch(SQLException e) {
  29.     Label not = new Label("Not connected:"+e.getMessage());
  30.     add(not);
  31.     }
  32.  
Greetz,

Kprojects
Aug 26 '08 #1
Share this Question
Share on Google+
2 Replies


100+
P: 283
Hello,

Expand|Select|Wrap|Line Numbers
  1. static String DBURL = "jdbc:mysql://localhost:3306/users_db?user=****&password=********";
  2. try {
  3.  
  4.                 try {
  5.                 try {
  6.                     try {
  7.                         Class.forName("com.mysql.jdbc.Driver").newInstance();
  8.                     } catch (InstantiationException ex) {
  9.  
  10.                     } catch (IllegalAccessException ex) {
  11.  
  12.                     }
  13.                 } catch (ClassNotFoundException ex) {
  14.  
  15.                 }
  16.                 } 
  17.                 catch (Exception ex) {
  18.  
  19.                 }
  20.    ......................                 
  21.  
  22.  
  23.     }
  24.     catch(SQLException e) {
  25.     Label not = new Label("Not connected:"+e.getMessage());
  26.     add(not);
  27.     }
  28.  
Greetz,

Kprojects
Hello, i dont really know what the problem here is, maybe you could expand more here like, a) What the error is. b) What output did you expected and what you get...

Also never swallow exceptions here. Exceptions are meant to be handled.

Expand|Select|Wrap|Line Numbers
  1. static String DBURL = "jdbc:mysql://localhost:3306/users_db?user=****&password=********";
  2. try {
  3.  
  4.                 try {
  5.                 try {
  6.                     try {
  7.                         Class.forName("com.mysql.jdbc.Driver").newInstance();
  8.                     } catch (InstantiationException ex) {
  9.                           ex.printStackTrace();
  10.  
  11.                     } catch (IllegalAccessException ex) {
  12.                           ex.printStackTrace();
  13.  
  14.                     }
  15.                 } catch (ClassNotFoundException ex) {
  16.                           ex.printStackTrace();
  17.                 }
  18.                 } 
  19.                 catch (Exception ex) {
  20.                     ex.printStackTrace();
  21.  
  22.                 }
  23.    ......................                 
  24.  
  25.  
  26.     }
  27.     catch(SQLException e) {
  28.     Label not = new Label("Not connected:"+e.getMessage());
  29.     add(not);
  30.     }
  31.  
Add these printStackTrace() statements and see if you get any error here.

regards,

ajos
Aug 26 '08 #2

10K+
P: 13,264
You need to read about signing applets, sandboxes and Applets vs JSPs. Then after that reading maybe you will throw away the Applet and use JSPs.
Aug 26 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.