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
- static String DBURL = "jdbc:mysql://localhost:3306/users_db?user=****&password=********";
- try {
- try {
- try {
- try {
- Class.forName("com.mysql.jdbc.Driver").newInstance();
- } catch (InstantiationException ex) {
- } catch (IllegalAccessException ex) {
- }
- } catch (ClassNotFoundException ex) {
- }
- }
- catch (Exception ex) {
- }
- Connection con = DriverManager.getConnection(DBURL);
- System.out.println("Succesfully connected!");
- Label ok = new Label("Connected");
- add(ok);
- }
- catch(SQLException e) {
- Label not = new Label("Not connected:"+e.getMessage());
- add(not);
- }
Kprojects