尝试连接时找不到H2驱动程序 [英] H2 driver not found when try to connect

查看:162
本文介绍了尝试连接时找不到H2驱动程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经回答了其他一些答案,但是无法解决我的问题.

I have gone through some other answers, but cannot get the solution to my problem.

我正在使用NetBeans 7.0.1和Win7上的最新版本的H2 DB.

I am using NetBeans 7.0.1 and the latest version of the H2 DB on Win7.

我成功使用了H2控制台工具,并且还在NetBeans中添加了驱动程序并能够连接(即,查看数据库,表,发出命令等).但是,从运行它的Java代码中,我得到消息:"java.lang.ClassNotFoundException:org.h2.Driver". 我的代码是:

I successfully use the H2 console tool and I have also added the driver in NetBeans and am able to connect (i.e. see the DB, tables, issue commands, etc). However from within my Java code when running it, I get the message: "java.lang.ClassNotFoundException:org.h2.Driver". My code is:

Class.forName("org.h2.Driver");
Connection conn = DriverManager.getConnection("jdbc:h2:tcp://localhost/~/testDB", "sa", "");
Statement query = null;
query = conn.createStatement();
String firstString = "INSERT INTO ......";
query.executeUpdate(firstString);

我还在类路径中添加了H2 jar文件(尽管我必须自己创建类路径并指向jar文件)-我进入了环境变量->用户变量

I have also added the H2 jar file in the classpath (although I had to create the classpath myself and point to the jar file) - I went to environment variables -> user variables

name=classpath value=.;C:\NetBeansProjects\testdemo\src\testdemo\DB\h2-1.3.165.jar

我做错了什么?

推荐答案

在源代码包下的库"部分中添加H2 jar文件.

Add the H2 jar file in the "Libraries" section under the source code packages.

这篇关于尝试连接时找不到H2驱动程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆