简体   繁体   中英

Cannot read table from oracle 11g database

This is my code:

import java.sql.*;

public class NewClass {
    public static void main(String[] args) {
       try{  
           Class.forName("oracle.jdbc.driver.OracleDriver");  
           Connection con=DriverManager.getConnection("jdbc:oracle:thin:@//127.0.0.1:1521/xe","system","apnair9902");  
           java.sql.Statement stmt = con.createStatement();  
           ResultSet rs=stmt.executeQuery("select * from INV_MASTER");  
           while(rs.next())  
                System.out.println(rs.getString(1)+"  "+rs.getString(2)+"  "+rs.getString(3));  
           con.close();
      }catch(Exception e){ System.out.println(e);}  
   }
}
`

I get the error:

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

I have created and edited the table from browser but the program cannot find the database.

You are selecting from a table that doesn't exist, or you are connecting to the database in a manner which leaves the table not accessible to this connection.

To create the table, connect to the database (in whatever manner you may) and run the appropriate SQL command. It resembles something like

CREATE TABLE INV_MASTER (
  ... column stuff ...
  ) ... optional stuff ...;

Of course, you need to know what to fill in for the columns and options appropriate to your particular needs.

If the table is already supposed to be there, then you are connecting to the wrong database, using the wrong user (which will put you in the wrong SCHEMA, or database "area") or someone who's handling the setup of the database hasn't setup the database yet.

Also, double check that the table you want really is called INV_MASTER and that you don't need to prefix it with a schema.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM