简体   繁体   English

使用mysql-connector将applet连接到数据库,并将外部jar添加到applet

[英]Connecting applet to database with mysql-connector and adding external jar to applet

I am having trouble with connecting my applet to the database which is on the same server as the applet. 我无法将小程序连接到与小程序位于同一服务器上的数据库。 It seem that the problem is that it can't find the com.mysql.jdbc.driver everytime i run the applet from the html it gives a classnotfound exception: com.mysql.jdbc.driver. 似乎问题在于,每次我从html运行applet时,都找不到com.mysql.jdbc.driver,它给出了一个classnotfound异常:com.mysql.jdbc.driver。 Code in the applet looks as follows: 小程序中的代码如下所示:

class Connect {
    private Connection con;
    private Statement st;
    private ResultSet rs;


    public Connect (){

        try{
            Class.forName("com.mysql.jdbc.Driver");
            con = DriverManager.getConnection("jdbc:mysql://ghghghg:3306/Roombooking", "root", "ghghgh?");
            st= con.createStatement();
            System.out.println("Connection established");
            JOptionPane.showMessageDialog(login, "IT WORKS!!");
        }
        catch(Exception ex){
            System.out.println("Error:" + ex);
            JOptionPane.showMessageDialog(login, ex);

        }
    }

I have tried adding the mysql-connector-java-5.1.30-bin.jar to the same folder as the applet on my server. 我尝试将mysql-connector-java-5.1.30-bin.jar添加到与服务器上小程序相同的文件夹中。 Also using the: 还使用:

archive="mysql-connector-java-5.1.30-bin.jar"

When i do that and also when i add the mysql-connector-java-5.1.30-bin.jar to the same folder as the applet it throws another exception: ExceptionInInitializer. 当我这样做时,以及当我将mysql-connector-java-5.1.30-bin.jar添加到与applet相同的文件夹中时,它将引发另一个异常:ExceptionInInitializer。

everything works when run by eclipse. 通过Eclipse运行时一切正常。

Can anyone help me i'm feeling completely stuck :( 谁能帮我,我感觉完全被困住了:(

Signed Your "mysql-connector-java-5.1.30-bin.jar" jar and replace it to your original jar. 在您的 “ mysql-connector-java-5.1.30-bin.jar” jar上签名 ,并将其替换为原始的jar。

Also Locate them explicitly in your applet tag. 还要在applet标签中明确找到它们。 Like Below 像下面

app.archive = '/esense/resources/lib/Applet.jar, /esense/resources/lib/mysql-connector-java-5.1.30.jar; app.archive ='/esense/resources/lib/Applet.jar,/esense/resources/lib/mysql-connector-java-5.1.30.jar;

Hope this ll work. 希望这会工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM