473,398 Members | 2,113 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Java applet jdbc error [MySQL DB]

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
2 1687
ajos
283 100+
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
r035198x
13,262 8TB
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

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

Similar topics

5
by: apchar | last post by:
I am trying to use php as a kind of servlet to act as a middle man between a java applet and mysql. I know java has jdbc but it's flakey and painful. php access to mysql is much nicer. So I have:...
8
by: Rhino | last post by:
I'm trying to use the JDBC Universal driver to get a Type 4 connection in a Java client program running under DB2 V8.2.1 but I keep getting a "connection refused: connect" message. I'm running...
2
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of...
6
by: haran22 | last post by:
verify and tell me what runtime error in this pgm import java.awt.*; import java.applet.*; import java.awt.event.*; import java.sql.*; public class screen extends Applet implements...
0
oll3i
by: oll3i | last post by:
package library.common; import java.sql.ResultSet; public interface LibraryInterface { public ResultSet getBookByAuthor(String author); public ResultSet getBookByName(String name);
1
by: nickyeng | last post by:
imageValue=null SEVERE:--> com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Column 'Gout_msgtext' cannot be null at...
2
by: dmstn | last post by:
Hey! I've got a little problem. I have to make a web site for a university essay. I curently have to create a search engine. Users can enter a hotel name in a search bar and results have to appear in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.