感谢您抽出宝贵的时间阅读。我知道有人问过类似的其他问题。我有的问题是我已经检查了所有相关问题,但仍然没有解决方案。我只是想选择一个列只是为了查看它的工作,但是如果我尝试选择所有列都没关系。
这是我的代码。...
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路径,它是相同的。已建立与数据库的连接。我什至在SQL Scrapbook中运行查询,都没有问题。我的用户名和密码是相同的。
这是控制台输出...
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))")
表已创建...
但是,我无法对此进行选择,插入或做任何事情。
答案 0 :(得分:1)
您以full_life = int(100)
while full_life > int(1):
do stuff
用户身份进行连接,因此这也是您要从中选择的默认架构。您尝试访问的表位于APP模式中。您需要在表名前面加上模式,例如
JavaFlix
或者,创建一个同义词,例如
SELECT * FROM APP.MOVIES
之后,您应该只可以从架构中执行CREATE SYNONYM MOVIES FOR APP.MOVIES
。