有jdbc连接数据库 执行查询语句报错:表不存在
------------------------------------------
代码:
package first;
import java.sql.*;
import oracle.sql.*;
import oracle.jdbc.pool.OracleDataSource;;public class PersonDao { /**
 * @param args
 * @throws Exception 
 */

// private final static String driver="oracle.jdbc.driver.OracleDriver";
// private final static String url="jdbc:oracle:thin:@localhost:1521:orcl";
// private final static String username="system";
// private final static String password="123456"; public static void main(String[] args) throws Exception {
// BaseOperation b=new BaseOperation();
// String sql="select * from person";
// ResultSet rs=b.executeQuery(sql);
// while(rs.next())
// {
// System.out.println(rs.getString("name"));
// }
//
// }
Connection conn = null;
Statement stmt = null;
ResultSet rs= null;
String url = "jdbc:oracle:thin:@127.0.0.1:1521:ORCL";
String username = "system";
String password = "123456";
DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
conn = DriverManager.getConnection(url, username, password);
stmt = conn.createStatement();
System.out.println("Link succeed!");
rs = stmt.executeQuery("select * from book");
while(rs.next())
{
int age = rs.getInt("age");
System.out.println(age);
}
}
}
--------------------------------------------
报错:
Link succeed!
Exception in thread "main" java.sql.SQLException: ORA-00942: table or view does not exist
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:124)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:304)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:271)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:622)
at oracle.jdbc.driver.T4CStatement.doOall8(T4CStatement.java:111)
at oracle.jdbc.driver.T4CStatement.execute_for_describe(T4CStatement.java:350)
at oracle.jdbc.driver.OracleStatement.execute_maybe_describe(OracleStatement.java:895)
at oracle.jdbc.driver.T4CStatement.execute_maybe_describe(T4CStatement.java:382)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:985)
at oracle.jdbc.driver.OracleStatement.executeQuery(OracleStatement.java:1124)
at first.PersonDao.main(PersonDao.java:38)

解决方案 »

  1.   

    用的是system用户连接
    你的book表不是在system用户下吧
    book表在哪个用户下就用哪个用户登录,不然的话就需要授权建同义词
    最好不要用sys,system等系统用户
      

  2.   

    吧这条语句在pl/sql里执行一下看结果
      

  3.   


    上面两个都正确。估计是这个book不是system里的对象了。或者建表的时候加了双引号。