开发eclipse插件,在插件中自动读取project的classLoader,因为project中存在数据库的驱动程序,但是在写完成以后发现提示如下错误:
No suitable driver
代码如下:
ProjectClassLoader projectLoader;
try {
projectLoader = new ProjectClassLoader((IJavaProject)JavaCore.create(tableNode.getSessionNode().getProfile().getProject()));
} catch (JavaModelException e) {
e.printStackTrace();
return ;
}
//old classloader
ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(projectLoader);
看到mysql的网站上有这样一段描述
"No suitable driver" is an error message that is given in either of two situations: the class was not found on the classpath, or the JDBC URL is wrong.
个人感觉应该是jar文件不能夹在造成的,怎么这样无法设置classLoader呢,比较奇怪。
终于解决了,原来DriverManager在内部处理的时候比较ClassLoader,自己定义的ClassLoader不起作用,可以采用下面的二种方式进行处理
1、通过Driver的方法connect来代替DriverManager的getConnection方法,这样是在Thread的classloader中调用,避免这个问题。
2、自己写一个DriverManager类,这样可以避免这个问题,
本来打算采用通过取得的classLoader来反射DriverManager的,但是提示不让反射,只能通过上面的二种方式解决了。
分享到:
相关推荐
服务器出现java.sql.SQLException No suitable driver found for 的
mysql5.6连接驱动jaf,可处理报错java.sql.SQLException: No suitable driver
包括 ImpalaJDBC3 ImpalaJDBC4 ImpalaJDBC41 三个版本的ImpalaJDBC连接所需Jar
详细介绍了在Tomcat中配置数据源JNDI的三种方法,其中第一种方法最好用,附带一部分源代码
Proxool连接池使用方法 首先, 你要把下载 proxool 的 lib 下面所有的 jar 文件, 放到 WEB-INF/lib 下面, 另外, 把你的 jdbc driver 也放到相同的 lib,
Flink JDBC 驱动程序Flink JDBC 驱动程序是一个 Java 库... 从下载 flink-jdbc-driver-(VERSION).jar 并将其添加到$HIVE_HOME/lib 。 运行 beeline 并连接到 Flink SQL 网关。 您可以在 url 的查询参数中指定规划器(
"No suitable driver found for jdbc:derby://localhost:1527/Employees" 解决上面问题,连接java和数据库会用到的包。
基于LPC17xx的CMSIS资源库 ... NXP Semiconductors also make no representation or warranty that such application will be suitable for the specified use without further testing or modification.
Choose "Search for a suitable driver for my device", and click Next. b. Check the box "Specify a location", and click Next. c. Browse to directory ..\USB_Bulk and select the file SilabsBulk.inf...
This book is suitable for anyone developing for Windows and Windows Mobile. Readers should be comfortable working with HTML and JavaScript. No previous experience with Microsoft technologies or ...
************************************************************ * Product: Intel(R) Chipset Software Installation Utility * Release: Production * Version: 7.2.2.1006 * Target Chipset(s)#: 955X/XM/975X/...
// This function creates a texture that is suitable to be stereoized by the driver. // Note that the parameters primarily come from nvstereo.h using nv::stereo::ParamTextureManagerD3D10; HRESULT ...
While no-one takes ownership of FreeBSD, the FreeBSD organisation is divided into core, committers and contributors and is part of the FreeBSD community that lives around it. Figure 3-1. The FreeBSD ...