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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27248147/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 02:39:05  来源:igfitidea点击:

java.sql.SQLException: ORA-00942: table or view does not exist

javaoraclejdbc

提问by rajasekhar

when i was trying to read data from Oracle database using the following code i was getting exception

当我尝试使用以下代码从 Oracle 数据库读取数据时出现异常

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

But this table is actually exist in my database when i use this command directly in the command prompt its working fine.And also for one table among the tables in database this code is working fine ,but for other table names its not working properly.So someone please explain why this is happening.

但是当我直接在命令提示符中使用此命令时,该表实际上存在于我的数据库中,它工作正常。而且对于数据库中的表中的一个表,此代码工作正常,但对于其他表名,它无法正常工作。所以有人请解释为什么会这样。

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)

采纳答案by rajasekhar

the problem is i am using multiple connections in the program to login to application i have used Oracle connection which is given as class level variable.And the client will be accessed his tables present in MySQL database using MySQL connection which is service method level variable.By mistakenly i have referred oracle connection variable and tried to acess mysql table

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

回答by devlopp

Check if you are using the correcte informations :

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

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

回答by Sush

Check each of the following:

检查以下各项:

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.

Contact the database administrator if the table needs to be created or if user or application privileges are required to access the table.

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

回答by Aliuk

I had this error when using persist() in Hibernate and the solution was to execute:

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

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