0

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.

6
  • Why are you connecting as SYSTEM? The table you're querying doesn't look like a standard system table. You should probably connect to the schema that owns that table (or at least, a schema that has select privileges on it). Commented Sep 14, 2014 at 13:56
  • System is the administrator i use to log in. The table is created and has content in it and i can view it myself. The only trouble i seem to have is retrieving it. I am using oracle 11g database which forces me to make a workspace before I can create tables, charts,etc. I do not understand the concept of this. If i try to connect by logging in directly to my workspace ID, it doesn't recognise the workspace. Im sorry if you don't understand I'm very new and not so sure how to work on jdbc or this website. But Thank you for your help Commented Sep 15, 2014 at 15:57
  • SYSTEM is a standard Oracle user. Generally you might use it to create one or more users (each of which will have an associated schema) and then log in to those users to create your application objects. Apex can do this for you as well, when you create a workspace. Commented Sep 15, 2014 at 22:47
  • You can't log in using a workspace ID, that's an internal apex thing. Commented Sep 15, 2014 at 22:48
  • Then how do I get the table from the work space to my program? Commented Sep 17, 2014 at 16:35

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I have made the database already as i have stated in the comment above, I do not want to waste time making tables in the program itself as it contains at least 150+ items. The table is already made on a workspace which i can access after logging in to my SYSTEM profile. If you could look into the structure of oracle 11g database that would be great. Sorry for bad question, I'm very new to jdbc and stack overflow. If you need more screenshots or information i am happy to upload
If you don't want to waste time making the table, exactly how do you intend to read it? If you know it is already there, then you are checking in the wrong spot. More information is not needed, you need to do work to figure out which problem(s) exist, and which ones don't.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.