Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Database/JDBC/SQL/JDO/Hibernate  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 如果从jar中查找驱动程序类
blog1984_111





发贴: 5
积分: 0
于 2008-01-21 08:13 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
如何从给定的驱动程序jar包中查找驱动程序类,即如何确定给定的jar包是驱动程序jar包?



作者 Re:如果从jar中查找驱动程序类 [Re:blog1984_111]
Jacob53





发贴: 6
积分: 0
于 2008-02-13 20:27 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
最笨的方法,把jar包里的类逐个用Class.forName()初始化,然后把连接字串传进去,得到连接了就说明jar包正确。


作者 Re:如果从jar中查找驱动程序类 [Re:blog1984_111]
rogertu





发贴: 3
积分: 0
于 2008-06-10 12:52 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
1. 创建一个URLClassLoader(设名称为classLoader),搜索路径为给定的jar包。

2. 遍历Jar包中的每个非目录ZipEntry(使用java.util.zip.ZipFile),获取其名称entryName
2.1 如果entryName以".class"结尾,获取其完整类名(即将entryName中的"/"全部替换为"."),设为className
2.2 使用classLoader加载名为className的类,设为class
2.3 判断class是否为java.sql.Driver的子类(java.sql.Driver.class.isAssignableFrom( class))且class为非抽象类(!Modifier.isAbstract( class.getModifiers( )))

不知道你使用过开源报表工具BIRT(http://www.eclipse.org/birt/phoenix/)没有,它是要动态管理用户提供的JDBC Driver jar/zip包并使用它们与数据库建立JDBC连接的;其基本实现原理如上所述


rogertu edited on 2008-06-10 12:54

www.actuatechina.com

A simple guy living a simple life in every simple day
作者 Re:如果从jar中查找驱动程序类 [Re:blog1984_111]
blog1984_111





发贴: 5
积分: 0
于 2008-06-19 17:24 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
谢谢rogertu 的帮助,问题已解决.



flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923