首先得把MYECLIPSE自带的JDK的DERBY数据库的JAR文件给导入工程,反正没事把几个都导进来,如下:
derby.jar,derbyclient.jar,derbynet.jar,derbyrun.jar,derbytools.jar.
myelipse 里 的DB Browser已经自带了myeclipse derby,直接启动服务,然后在app 的table建表,如videoinfo.
写连接数据的类,如下。
Java代码 收藏代码
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.apache.derby.impl.sql.compile.StaticClassFieldReferenceNode;
public class DBmanager {
public static void main(String[] args) throws Exception {
Class.forName("org.apache.derby.jdbc.ClientDriver");
Connection conn = java.sql.DriverManager.getConnection(
"jdbc:derby://localhost:1527/MyEclipse", "classiccars",
"classiccars");
Statement stmt = conn.createStatement();
ResultSet rs = stmt
.executeQuery("select v.id, v.name,v.videopath from app.videoinfo v");
while (rs.next()) {
System.out.print(rs.getString("id") + "; " + rs.getString("name"));
System.out.println(" ");
}
rs.close();
stmt.close();
conn.close();
}
}