1.系统基本信息
Java Version: 1.6.0_11
JRE Version: 6.0
OS name: Windows Server 2008
Eclipse Version: 3.4
Derby Version: 10.4.2
2.我正在研究JDK 6.0中RowSet及其子接口的使用方法,详见http://www.ibm.com/developerworks/cn/java/j-lo-java6rowset.
在用JDBC连接Derby时出现了问题:
我安装了Derby的Eclipse插件:derby_core_plugin_10.4.2和derby_ui_plugin_1.1.2,并在IJ控制台新建了个数据库testdb,然后我写代码访问数据库时却提示出错:(1)java.lang.ClassNotFoundException: jdbc:derby://localhost:1527/E:/Practice/JavaEE/JDK 1.6/derbydb/testdb;create=true
(2)Exception in thread "main" java.sql.SQLException: No suitable driver found for org.apache.derby.jdbc.ClientDriver
package jdk6.rowset.ibm;
public class DBCreator {
/**
* 数据库工具类,提供了连接数据库的基本信息
*/
public static final String DRIVER = "org.apache.derby.jdbc.ClientDriver";
public static final String DERBY_URL = "jdbc:derby://localhost:1527/E:/Practice/JavaEE/JDK 1.6/derbydb/testdb;create=true";
public static final String SQL_SELECT_CUSTOMERS = "SELECT * FROM customer";
public static final String SQL_SELECT_ORDERS = "SELECT * FROM orders";
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}
[code=Java]package jdk6.rowset.ibm;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.sql.rowset.CachedRowSet;
import com.sun.rowset.CachedRowSetImpl;
public class CachedRowSetDemo {
/**
* @param args
*/
public static Connection conn = null;
public static Statement stmt = null;
public static void fillRowSetWithExecute(CachedRowSet cachedRS)
throws SQLException {
cachedRS.setUrl(DBCreator.DERBY_URL);
// 使用 execute() 填充 CachedRowSet 时,需要设置数据库连接参数和查询命令 command
cachedRS.setCommand(DBCreator.SQL_SELECT_CUSTOMERS);
// Apache Derby的默认数据库用户名和密码均为APP
cachedRS.execute();
}
public static void main(String[] args) throws SQLException,
ClassNotFoundException, InstantiationException,
IllegalAccessException {
// TODO Auto-generated method stub
try {
Class.forName(DBCreator.DERBY_URL).newInstance();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
conn = DriverManager.getConnection(DBCreator.DRIVER);
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
CachedRowSet cachedRS = new CachedRowSetImpl();
fillRowSetWithExecute(cachedRS);
stmt.close();
conn.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}code]
我的困惑主要是:
当不使用derby的eclipse插件时,可以正常连接;现在用了插件,并在插件的控制台下写的sql语句,却不能连接,请朋友们帮忙参考一下,谢谢!
PS: derby.jar derbyclient.jar derbytools.jar derbyrun.jar derbynet.jar以及derby的eclipse插件均已经添加进了classpath,
Eclipse的工程中也添加了,StartNetworkServer也已经在控制台启动,系统环境变量也设置过了