java.sql.SQLException:ORA-00942:表或视图不存在

问题描述 投票:0回答:4

[当我尝试使用以下代码从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)
java oracle jdbc
4个回答
0
投票

检查以下各项:

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.

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


0
投票

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

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

0
投票

问题是我在程序中使用多个连接登录到应用程序,我使用了作为类级别变量给出的Oracle连接。然后,将使用服务方法级别的MySQL连接访问客户端在MySQL数据库中的表。 variable.By错误地引用了oracle连接变量并尝试访问mysql表

© www.soinside.com 2019 - 2024. All rights reserved.