开发者

I'm having trouble embedding HSQLDB into a simple Java (Eclipse) project

After reading up on some options (sqlite, derby etc...), I've decided to throw down with HSQLDB. I've downloaded it, read up on it and followed a 'hello world' type intro to it, and am now stuck.

I believe that you have to put the hsqldb.jar file in the src folder, so I did exactly that. Then I made a reference to the package with Eclipse by going into Run -> Run Configurations, then going into the Classpath tab, then clicking User Entries, then add External Jar, and selecting hsqldb.jar.

I get this :

java.lang.ClassNotFoundException: org.hsqldb.jdbcDriver

Here's my code :

package mysqlite;

import java.sql.*;

public class myclass {
    public static void main(String[] args) {
        try {
            Class.forName("org.hsqldb.jdbcDriver");

            String url = "jdbc:hsqldb:db";
            String user = "aU开发者_StackOverflow中文版ser";
            String password = "";

            Connection conn = DriverManager.getConnection(url, user, password);
        }
        catch(Exception e) {
            System.out.println(e.toString());           
        }
    }
}

I understand it's unable to find a class, but I thought that was what the hsqldb.jar provided.


No, you do not have to put it into src folder. src is for source files (*.java). You have to add this jar into your classpath: click on project properties, choose "Java build path", select tab "Libraries" and add the jar here.

The jar can be stored anywhere in your file system. Sometimes people create lib directory under project home and put all 3rd party dependencies there.


Try putting the .jar here:

<YOUR_JAVA_HOME>\jre\lib\ext
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜