我正在尝试使用 derby 嵌入式数据库制作一个 java 桌面数据库应用程序,我遇到了一些我无法完全解决的问题,我已经(很多)搜索了答案,找到了一些,但他们无法解决我的问题,所以我决定自己提出一个问题。我在netbeans上创建了数据库,就像一大堆教程一样,下载了derby.jar并添加到项目的库中,但是当我尝试在我创建的数据库表中插入一些数据时说表不存在。我很确定我错过了一些非常愚蠢的东西,但我自己无法弄清楚,所以任何帮助都会非常感激。我是所有这些 java 数据库开发的新手,我只在 c# 上创建了本地数据库
PS:架构是'APP'之一,我尝试使用“INSERT INTO APP.PACIENTE(ID,NOME)VALUES(1,'victor')”但这也不起作用
public class BancoDados {
private static String url = "jdbc:derby:MeuBancoDados;create=true";
private static String driver = "org.apache.derby.jdbc.EmbeddedDriver";
static Connection conn;
static Statement sta;
public static void insert() throws SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException {
conn = null;
sta = null;
try {
Class.forName(driver);
conn = DriverManager.getConnection(url);
sta = conn.createStatement();
sta.executeUpdate("INSERT INTO PACIENTE (ID, NOME) VALUES (1, 'victor')");
sta.close();
conn.close();
System.out.println("Inserido com sucesso!");
} catch (Exception e) {
System.err.println("Exception: " + e.getMessage());
}
}
}
我得到这个错误:
Exception in thread "main" ERROR 42X05: Table 'PACIENTE' does not exist.
at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
at org.apache.derby.impl.sql.compile.DMLModStatementNode.verifyTargetTable(Unknown Source)
at org.apache.derby.impl.sql.compile.InsertNode.bind(Unknown Source)
at org.apache.derby.impl.sql.GenericStatement.prepMinion(Unknown Source)
at org.apache.derby.impl.sql.GenericStatement.prepare(Unknown Source)
at org.apache.derby.impl.sql.conn.GenericLanguageConnectionContext.prepareInternalStatement(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedStatement.execute(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedStatement.executeUpdate(Unknown Source)
at projcad.BancoDados.insert(BancoDados.java:31)
at projcad.projcad.main(projcad.java:8)
Java 结果:1