感谢您抽出宝贵时间阅读。我知道其他问题也有类似之处。我遇到的问题是我已经检查了相关问题中的所有问题,仍然没有解决方案。我只是试图选择一个列只是为了看它工作,但是如果我尝试选择所有这些并不重要。
这是我的代码....
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.ResultSet;
public class DBConnection {
private static final String DRIVER = "org.apache.derby.jdbc.EmbeddedDriver";
private static String JDBC_URL;
Connection con;
public DBConnection() throws SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException {
Class.forName(DRIVER).newInstance();
con = DriverManager.getConnection(connectionUrl());
if(con != null)
System.out.println("Connection Established");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("select * from MOVIES");
while(rs.next()) { String movieName = rs.getString(1);
System.out.println(movieName); }
rs.close();
con.close();
}
private static final String connectionUrl() {
JDBC_URL = "jdbc:derby:MoviePlayer_JavaFlix;create=true;USER = JavaFlix; password = 123";
return JDBC_URL;
}
}
我检查了数据库属性中的url路径,它是identicle。建立与数据库的连接。我甚至在SQL Scrapbook中运行了查询并且没有遇到任何问题。我的用户名和密码是identicle。
这是控制台输出......
Connection Established
Exception in thread "main" java.sql.SQLSyntaxErrorException: Table/View 'MOVIES' does not exist.
at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedStatement.execute(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedStatement.executeQuery(Unknown Source)
at data.source.db.DBConnection.<init>(DBConnection.java:23)
at data.source.db.Main.main(Main.java:8)
Caused by: ERROR 42X05: Table/View 'MOVIES' does not exist.
at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
at org.apache.derby.impl.sql.compile.FromBaseTable.bindTableDescriptor(Unknown Source)
at org.apache.derby.impl.sql.compile.FromBaseTable.bindNonVTITables(Unknown Source)
at org.apache.derby.impl.sql.compile.FromList.bindTables(Unknown Source)
at org.apache.derby.impl.sql.compile.SelectNode.bindNonVTITables(Unknown Source)
at org.apache.derby.impl.sql.compile.DMLStatementNode.bindTables(Unknown Source)
at org.apache.derby.impl.sql.compile.DMLStatementNode.bind(Unknown Source)
at org.apache.derby.impl.sql.compile.CursorNode.bindStatement(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)
... 4 more
这是我的数据库位置......
这是我的文件夹路径... C:\ Users \ Banan \ eclipse-workspace \ MoviePlayer_JavaFlix
我想我可能发现了一些可能导致问题的问题......
当我运行st.executeUpdate("CREATE TABLE movies (ID INT PRIMARY KEY, movie_name VARCHAR(50))")
创建一个表...
但是,我不能选择,插入或做任何事情。
您正在以JavaFlix
用户身份进行连接,因此这也是您选择的默认架构。您尝试访问的表位于APP架构中。您需要在表名前添加模式,例如
SELECT * FROM APP.MOVIES
或者,创建一个同义词,如
CREATE SYNONYM MOVIES FOR APP.MOVIES
之后你应该能够从你的架构中做SELECT * FROM MOVIES
。