我整天都在搜索有关此类似问题的文档,但似乎找不到答案。我很容易在服务器客户端模式下找到了一个数据库(org.apache.derby.jdbc.ClientDriver),但是我对嵌入式模式下的结果数据库感到困惑(org.apache.derby.jdbc.EmbeddedDriver)。
一切似乎都很好,与数据库的连接是成功的,但它总是给我这个错误:
java.sql.SQLSyntaxErrorException:表/视图“APP.TABELJEMBATAN”不存在。
http://i1263.photobucket.com/albums/ii633/lindafitriani/javadb4.jpg
我的数据库存在,见下文:
http://i1263.photobucket.com/albums/ii633/lindafitriani/javadb1.jpg http://i1263.photobucket.com/albums/ii633/lindafitriani/javadb2.jpg
这是我的 derby.log 文件的内容:
2012-06-30 18:08:34.170 GMT:引导 Derby 版本 Apache 软件基金会 - Apache Derby - 10.5.3.0 - (802917):数据库目录 C:\Users\Linda 上的实例 a816c00e-0138-3e94-78a3-000000b35a08 Fitriani\Documents\NetBeansProjects\Jembatan\Jembatan2
数据库类加载器已启动 - derby.database.classpath=''
http://i1263.photobucket.com/albums/ii633/lindafitriani/javadb3.jpg
数据库位置是正确的(在我的工作目录上),但 derby.database.classpath 是空的......有人知道如何解决这个问题吗?
这是我的代码:
package jembatan;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
/**
*
* @author Linda Fitriani
*/
public class DBConnect {
private static Connection conn;
private static String url = "jdbc:derby:Jembatan2;create=true;";
private static String user = "APP";
private static String pass = "linda";
public static Connection connect() throws SQLException{
try{
Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
}catch(ClassNotFoundException cnfe){
System.err.println("Error: ClassNotFoundException"+cnfe.getMessage());
}catch(InstantiationException ie){
System.err.println("Error:InstantiationException"+ie.getMessage());
}catch(IllegalAccessException iae){
System.err.println("Error:IllegalAccessException"+iae.getMessage());
}
conn = DriverManager.getConnection(url,user,pass);
return conn;
}
public static Connection getConnection() throws SQLException, ClassNotFoundException{
if(conn !=null && !conn.isClosed())
return conn;
connect();
return conn;
}
}
private void buildData(){
Connection c ;
data = FXCollections.observableArrayList();
try{
c = DBConnect.connect();
//SQL FOR SELECTING ALL OF APP.TABELJEMBATAN
String SQL = "select * from APP.TABELJEMBATAN";
//ResultSet
ResultSet rs = c.createStatement().executeQuery(SQL);
/**********************************
* TABLE COLUMN ADDED DYNAMICALLY *
**********************************/
for(int i=0 ; i<rs.getMetaData().getColumnCount(); i++){
//We are using non property style for making dynamic table
final int j = i;
TableColumn col = new TableColumn(rs.getMetaData().getColumnName(i+1));
col.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<ObservableList,String>,ObservableValue<String>>(){
public ObservableValue<String> call(TableColumn.CellDataFeatures<ObservableList, String> param) {
return new SimpleStringProperty(param.getValue().get(j).toString());
}
});
tableview.getColumns().addAll(col);
col.setMinWidth(200);
System.out.println("Column ["+i+"] ");
}
/********************************
* Data added to ObservableList *
********************************/
while(rs.next()){
//Iterate Row
ObservableList<String> row = FXCollections.observableArrayList();
for(int i=1 ; i<=rs.getMetaData().getColumnCount(); i++){
//Iterate Column
row.add(rs.getString(i));
}
System.out.println("Row [1] added "+row );
data.add(row);
}
//FINALLY ADDED TO TableView
tableview.setItems(data);
}catch(Exception e){
e.printStackTrace();
System.out.println("Error on Building Data");
}
}