Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Using Mysql connector/J

  • 29-03-2006 11:42am
    #1
    Closed Accounts Posts: 999 ✭✭✭


    Hi,


    I'm trying to set up a small java app that will connect to a mysql database. I'm trying to learn how to write database applications. At the moment the code is very simple as I'm just trying to create a db connection.
    The Code:

    [PHP]
    import javax.swing.JPanel;
    import javax.swing.JButton;
    import javax.swing.JLabel;
    import javax.swing.JApplet;
    import java.applet.AppletContext;
    import java.awt.Container;
    import javax.swing.SwingConstants;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.SQLException;
    import javax.swing.JTextArea;
    import java.awt.GridBagLayout;
    import java.awt.GridBagConstraints;
    import org.gjt.mm.mysql.Driver;

    public class Phonebook extends JApplet
    {

    public String testConnection()
    {
    String output;

    try
    {
    try
    {
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    }
    catch(ClassNotFoundException cnfe)
    {
    output = "Failed to load database driver - Class Not Found Exception";
    System.out.println("\n\n\n" + cnfe + "\n\n\n");
    return output;
    }
    catch(ExceptionInInitializerError eiie)
    {
    output = "Failed to load database driver - Exception In Initializer Error";
    return output;
    }
    catch(InstantiationException ie)
    {
    output = "Failed to load database driver - Instantiation Exception";
    return output;
    }
    catch(IllegalAccessException iae)
    {
    output = "Failed to load database driver - Illegal Access Exception";
    return output;
    }


    Connection con = DriverManager.getConnection ("jdbc:mysql://localhost/phonebook", "pbook", "L0g1n");
    output = "Connection to database successful";

    }
    catch(SQLException sqle)
    {
    output = "Failed to make database connection - SQL Exception";
    }

    return output;
    }

    public void init()
    {
    String status = "Update Pending . . .";
    Container contentPane = getContentPane();
    JPanel mainPanel = new JPanel();
    JTextArea jta = new JTextArea(status, 40, 10);

    GridBagLayout gridbag = new GridBagLayout();
    GridBagConstraints gbcs = new GridBagConstraints();
    mainPanel.setLayout(gridbag);
    gbcs.fill = GridBagConstraints.BOTH;
    gbcs.weightx = 1.0;
    gridbag.setConstraints(jta, gbcs);
    mainPanel.add(jta);

    status = this.testConnection();
    jta.setText(status);

    contentPane.add(mainPanel );
    }
    }[/PHP]
    When I compile and try to run this using the appletviewer I get the following error,
    java.lang.ExceptionInInitializerError
    at com.mysql.jdbc.Connection.<init>(Connection.java:1176)
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java
    :266)
    at java.sql.DriverManager.getConnection(DriverManager.java:525)
    at java.sql.DriverManager.getConnection(DriverManager.java:171)
    at Phonebook.testConnection(Phonebook.java:52)
    at Phonebook.init(Phonebook.java:79)
    at sun.applet.AppletPanel.run(AppletPanel.java:374)
    at java.lang.Thread.run(Thread.java:595)
    Caused by: java.lang.RuntimeException: Unable to initialize character set mappin
    g tables
    at com.mysql.jdbc.CharsetMapping.<clinit>(CharsetMapping.java:73)
    ... 8 more

    Now I've looked this bug up Here and apparently there Is a patch.
    The thing is I can't figure out from this patch what I need to do to make it work.

    Can anyone here help me out with getting this to work?


Comments

  • Registered Users, Registered Users 2 Posts: 2,013 ✭✭✭lynchie


    Try using the latest snapshot of connector j. This is the development version of the driver which would have all new patches added to it.


  • Closed Accounts Posts: 999 ✭✭✭Raz


    Lynchie, you wouldn't believe how grateful I am to you. The solution provided worked a charm. Thank you so much.


Advertisement