beanshell jdbc连接、类加载

发布于 2024-09-25 13:30:50 字数 716 浏览 1 评论 0原文

我想在 beanshell 脚本中连接到 hsqldb。

我在加载类时遇到问题,我之前写过并已回复。

代码看起来像这样:

    Connection conn = null;

    try {
            getClass("org.hsqldb.jdbcDriver").newInstance();
            conn =  DriverManager.getConnection("jdbc:hsqldb:file:C:/testdata/tdb","SA","");
            System.out.println("Connection established");
    }

我收到此错误:

java.sql.SQLException: No suitable driver found for jdbc:hsqldb:file:C:/testdata/tdb

我也尝试注册驱动程序,但我没有工作

DriverManager.register(getClass("org.hsqldb.jdbcDriver").newInstance())

此代码已经在java中工作(而不是使用 Class.forName() 的 getClass() ) beanshell 还需要什么来运行这段代码?

谢谢, 比拉尔

i want to connect to a hsqldb in beanshell script.

i had problems while loading class, i wrote it before and it was replied.

the code looks like that:

    Connection conn = null;

    try {
            getClass("org.hsqldb.jdbcDriver").newInstance();
            conn =  DriverManager.getConnection("jdbc:hsqldb:file:C:/testdata/tdb","SA","");
            System.out.println("Connection established");
    }

and i am getting this error:

java.sql.SQLException: No suitable driver found for jdbc:hsqldb:file:C:/testdata/tdb

and i tried to register Driver too but i didn't worked

DriverManager.register(getClass("org.hsqldb.jdbcDriver").newInstance())

this code works already in java (instead of getClass() using Class.forName())
what does beanshell need anymore to work this code?

Thanks,
Bilal

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

歌枕肩 2024-10-02 13:30:50

我放弃了这一点,与其他类型的对象相比,没有办法动态加载 JDBC 类,相反,我现在使用 Runtime exec 来调用 DB 的命令行程序。另外,beanshell 有一个“exec()”方法。

幸运的是,我所需要的只是针对数据库运行脚本,而不是实际与数据库交互,所以这对我有用。

另外,JDBC 不会为您加载的原因是 Beanshell 有时会加载它自己的类加载器(而不是默认的类加载器)。当您尝试在 Beanshell 脚本内动态加载 jar 时,尤其会发生这种情况。如果您将 jdbc.jar 放入 Javasoft/ext 目录中,在这种情况下我相信它将进入默认的类加载器。另外,如果您的 Beanshell 脚本足够小心不触发新的类加载器,那可能会起作用以及。换句话说,不要在脚本中调用“addClassPath”等。

I gave up on this , there was no way to dynamically load JDBC classes as opposed to other types of objects, and instead, I now use Runtime exec to call the command line program for the DB . Also , beanshell has a "exec()" method.

Luckily, all I needed was to run scripts against the DB rather than actually interact with the DB , and so this works for me.

Also, the reason JDBC wont load for you is because Beanshell sometimes will load its own classloader (instead of the default classloader). This happens especially if you try to dynamically load jars inside the Beanshell script. If you put your jdbc.jar into Javasoft/ext directory, in that case I believe it will get into the default classloader. Also, if your Beanshell script is careful enough not to trigger the new classloader, that may work as well. In other words, dont call "addClassPath" in your script, among other things.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文