链接oracle出现:“表或视图不存在”异常
连接Oracle数据库的函数代码如下:Java code
public static final String DRIVER="oracle.jdbc.driver.OracleDriver";
public static final String URL="jdbc:oracle:thin:@192.168.1.100:1521:gwl";
public static final String DBNAME="order1";
public static final String DBPWD="bdqn";
public Connection getConnection(){
Connection conn=null;
try {
Class.forName(DRIVER);
conn=DriverManager.getConnection(URL,DBNAME,DBPWD);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return conn;
}
这段代码返回的conn是不为空的,貌似没问题。下面是我查询一张表的所有内容的代码:Java code
public void selectAll(){
Connection conn=getConnection();
PreparedStatement pstmt = null;
ResultSet rs=null;
try {
pstmt = conn.prepareStatement("select * from orderitem");
rs=pstmt.executeQuery();
while(rs.next()){
System.out.print(rs.getInt(1));
System.out.print(rs.getString(2));
System.out.print(rs.getFloat(3));
System.out.println(rs.getInt(4));
}
} catch (SQLException e) {
e.printStackTrace();
}finally{
closeAll(conn,pstmt,rs);
}
}
测试的main函数如下:Java code
public static void main(String[] args){
BookOrder bo=new BookOrder();
bo.selectAll();
}
报告异常如下:java.sql.SQLException: ORA-00942: 表或视图不存在
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:745)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:216)
at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:810)
at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1039)
at oracle.jdbc.driver.T4CPreparedStatement.executeMaybeDescribe(T4CPreparedStatement.java:850)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1134)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3339)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3384)
at com.gwl.all.BookOrder.selectAll(BookOrder.java:64)
at com.gwl.all.BookOrder.main(BookOrder.java:55)
让我疑惑的是oracle中明明存在book这张表,用户名和密码也是正确的,链接函数也正常不知为何,求解!谢谢!
------解决方案--------------------
1 数据库中没有orderitem
2 public static final String URL="jdbc:oracle:thin:@192.168.1.100:1521:gwl";
public static final String DBNAME="order1";
public static final String DBPWD="bdqn";
这连接的不是你的机器 或者用户order1下没有orderitem表
------解决方案--------------------
public void selectAll(){ <