Could not get JDBC Connection,请教高手。

arthas_sh 2010-03-20 04:45:51
请教个问题。在myeclipse启动tomcat,工程登录时,会报错:
org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Cannot create JDBC driver of class 'COM.ibm.db2.jdbc.app.DB2Driver' for connect URL 'jdbc:db2:cms'
Caused by: java.sql.SQLException: Cannot create JDBC driver of class 'COM.ibm.db2.jdbc.app.DB2Driver' for connect URL 'jdbc:db2:cms'
不在eclipse中启动tomcat,由tomcat-6.0.18\bin下的startup.bat启动tomcat,则没有任何错误,可以正常使用工程。
我的环境是 jdk1.6 tomcat6 myeclipse7
DB2是装在本机上了。在网上找了一些相关的解决方法都不管用。只好在这里请教各位了。
...全文
6987 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
arthas_sh 2010-03-22
  • 打赏
  • 举报
回复
问题依旧,眼泪依旧。
我的驱动类是COM.ibm.db2.jdbc.app.DB2Driver,按你的方法做了回。呵呵,没改前也没有写错。类名是从myeclipse->DB Browser里复制过来的。数据库可以连通。
我在想是不是myeclipse的问题。从startup.bat启动tomcat,工程一点问题也没有。只要从myeclipse里启tomcat,就Could not get JDBC Connection。可是myeclipse就是一个IDE能有什么毛病。而且从前使用也没有问题。这能是什么毛病呢?
星辰企业 2010-03-21
  • 打赏
  • 举报
回复
驱动的类名写错了! 你可以到com.ibm.db2.jcc.DB2Driver这里面打到DB2Driver这个.class文件后再复制他的名字再粘贴再删除.class就可以了!就不会出现这样的问题了!!!!
arthas_sh 2010-03-21
  • 打赏
  • 举报
回复
jar包都在classpath里,工程是好用的,只是在myeclipse里启动tomcat,再用工程就报错。真是日了。
现在得用startup.bat启动tomcat使用工程才不报错。改程序时麻烦了些。全是眼泪。
bayougeng 2010-03-20
  • 打赏
  • 举报
回复
估计是因为你那个jar放到了WEB-INF/lib下,却没有加入到eclipse的classpath里。
arthas_sh 2010-03-20
  • 打赏
  • 举报
回复
试过楼上两位说的办法,错误依旧。
这次的问题挺奇怪的,由tomcat启动工程没有任务报错。
只是在myeclipse中启动tomcat6,工程登录时报错。
usherlight 2010-03-20
  • 打赏
  • 举报
回复
1. 将类名改为:com.ibm.db2.jcc.DB2Driver
2. 确保db2的包在类路径下。
amos1989 2010-03-20
  • 打赏
  • 举报
回复
'COM.ibm.db2.jdbc.app.DB2Driver' 把COM改成小写。试试,这个是区分大小写的
在Java下连接SQLite数据库 一、下载SQLite数据库的JDBC:http://www.zentus.com/sqlitejdbc/ 二、将下载到的包解压后得到jar包放到%JAVA_HOME%\lib下,并且将其添加到ClassPath系统环境变量中。一定要保证在类路径ClassPath中有该jar包,并且保证在JAVA库路径JAVA Library Path中有本地库Native Library(\workspace\"Web应用"\WebRoot\WEB-INF\lib\下最好也要加入该jar包)。"SQLite.JDBCDriver"作为JDBC的驱动程序类名。连接JDBC的URL格式为jdbc:sqlite:/path。这里的path为指定到SQLite数据库文件的路径,例如: jdbc:sqlite://dirA/dirB/dbfile jdbc:sqlite://DRIVE:/dirA/dirB/dbfile jdbc:sqlite://COMPUTERNAME/shareA/dirB/dbfile 三、下面是使用SQLite的两段代码以供参考: 代码段1: 1 import java.sql.*; 2 import org.sqlite.JDBC; 3 4 public class SQLiteTest { 5 public static void main(String[] args) { 6 try { 7 // The SQLite (3.3.8) Database File 8 // This database has one table (pmp_countries) with 3 columns (country_id, country_code, country_name) 9 // It has like 237 records of all the countries I could think of. 10 String fileName = "c:/pmp.db"; 11 // Driver to Use 12 // http://www.zentus.com/sqlitejdbc/index.html 13 Class.forName("org.sqlite.JDBC"); 14 // Create Connection Object to SQLite Database 15 // If you want to only create a database in memory, exclude the +fileName 16 Connection conn = DriverManager.getConnection("jdbc:sqlite:"+fileName); 17 // Create a Statement object for the database connection, dunno what this stuff does though. 18 Statement stmt = conn.createStatement(); 19 // Create a result set object for the statement 20 ResultSet rs = stmt.executeQuery("SELECT * FROM pmp_countries ORDER BY country_name ASC"); 21 // Iterate the result set, printing each column 22 // if the column was an int, we could do rs.getInt(column name here) as well, etc. 23 while (rs.next()) { 24 String id = rs.getString("country_id"); // Column 1 25 String code = rs.getString("country_code"); //

58,454

社区成员

发帖
与我相关
我的任务
社区描述
Java Eclipse
社区管理员
  • Eclipse
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧