开发者

beanshell jdbc connection, class loading

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.jdbcDr开发者_StackOverflowiver").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


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜