【问题标题】:java.sql.SQLException: ORA-00942: table or view does not existjava.sql.SQLException: ORA-00942: 表或视图不存在
【发布时间】:2015-01-30 14:59:18
【问题描述】:

当我尝试使用以下代码从 Oracle 数据库中读取数据时,我遇到了异常

PreparedStatement pst=con.prepareStatement("SELECT * FROM TBLUSER");
pst.executeQuery();

但是当我直接在命令提示符中使用此命令时,此表实际上存在于我的数据库中正确。所以请有人解释为什么会这样。

java.sql.SQLException: ORA-00942: table or view does not exist
        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:743)
        at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:216)
        at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:799)
        at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1038)
        at oracle.jdbc.driver.T4CPreparedStatement.executeMaybeDescribe(T4CPreparedStatement.java:839)
        at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1133)
        at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3285)
        at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3329)
        at com.symp.ControllerServlet.service(ControllerServlet.java:302)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
        at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
        at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
        at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:315)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:745)

【问题讨论】:

  • 嗯,您使用的是什么 JDBC 驱动程序? com.mysql.jdbc.Driver 还是 oracle.jdbc.driver.OracleDriver?如果您使用的是 oracle.jdbc.driver.OracleDriver,那么您使用的是错误的驱动程序。
  • 确保该表已授予您从 java 访问数据库的用户!
  • @vzamanillo,驱动出错时不会抛出 ORA-00942 异常!
  • @hemanth,使用 Oracle JDBC 驱动程序连接到 MySQL?嗯?
  • 如果你得到一个 ORA-xxxx 错误你没有连接到 MySQL,那是不可能的,这就是我想说的。

标签: java oracle jdbc


【解决方案1】:

检查您是否使用了正确的信息:

String url = "jdbc:mysql://localhost:3306/YOUR_SCHEMA";
Driver driver = com.mysql.jdbc.Driver();
String userName = "user";
String password = "pass";

【讨论】:

    【解决方案2】:

    检查以下各项:

    1) the spelling of the table or view name.
    2) that a view is not specified where a table is required.
    3) that an existing table or view name exists.
    

    如果需要创建表或者需要用户或应用程序权限来访问表,请联系数据库管理员。

    【讨论】:

      【解决方案3】:

      问题是我在程序中使用了多个连接来登录应用程序级别变量。我错误地引用了 oracle 连接变量并尝试访问 mysql 表

      【讨论】:

        【解决方案4】:

        在 Hibernate 中使用 persist() 时出现此错误,解决方案是执行:

        grant all on <schema>.<table> to <user>;
        grant all on <schema>.<sequence> to <user>;
        

        【讨论】:

          猜你喜欢
          • 2020-10-16
          • 2019-01-22
          • 1970-01-01
          • 2015-11-09
          • 2011-12-10
          • 2016-08-23
          • 2018-02-05
          • 1970-01-01
          相关资源
          最近更新 更多