Java applet jdbc error [MySQL DB]

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kprojects
    New Member
    • Aug 2008
    • 3

    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

    Code:
    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);
        }
    Greetz,

    Kprojects
  • ajos
    Contributor
    • Aug 2007
    • 283

    #2
    Originally posted by kprojects
    Hello,

    Code:
    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) {
                        
                    }
       ......................                 
    
       
        }
        catch(SQLException e) {
        Label not = new Label("Not connected:"+e.getMessage());
        add(not);
        }
    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.

    Code:
    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) {
                              ex.printStackTrace();
                           
                        } catch (IllegalAccessException ex) {
                              ex.printStackTrace();
                            
                        }
                    } catch (ClassNotFoundException ex) {
                              ex.printStackTrace();
                    }
                    } 
                    catch (Exception ex) {
                        ex.printStackTrace();
                        
                    }
       ......................                 
    
       
        }
        catch(SQLException e) {
        Label not = new Label("Not connected:"+e.getMessage());
        add(not);
        }
    Add these printStackTrace () statements and see if you get any error here.

    regards,

    ajos

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #3
      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.

      Comment

      Working...