Link to home
Start Free TrialLog in
Avatar of KAMAU
KAMAU

asked on

java.sql.SQLSyntaxErrorException: Table/View 'ADMIN.TABLE1' does not exist.

i'm a newbie to java and am trying a few examples. I followed the code shown in http://wiki.netbeans.org/wiki/view/GetStartedwithJavaDB.
In runtime i can see the table, i can connect to it and i can insert and select records. However when i run the code shown below i get the error message
java.sql.SQLSyntaxErrorException: Table/View 'ADMIN.TABLE1' does not exist.

/*
 * Main.java
 *
 * Created on 15 November 2007, 14:22
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */
 
package javadbdemo;
import java.sql.*;
/**
 *
 * @author lassogba
 */
public class Main {
    
    /** Creates a new instance of Main */
    public Main() {
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args){
             // TODO code application logic here
        try{
            Class.forName("org.apache.derby.jdbc.embeddeddriver");
           }catch(ClassNotFoundException e)
              {
              System.out.println("e");
              }
        
        try{
            Connection con=DriverManager.getConnection("jdbc:derby://localhost:1527/SimpleDBDemo2","admin","password");
     
            Statement stmt=con.createStatement();
            ResultSet rs=stmt.executeQuery("Select * from admin.Table1");
            System.out.println("rs");
            while (rs.next()){
                String s=rs.getString("Name");
                float n=rs.getFloat("Age");
                System.out.println(s+" " + n);
             }
                 }catch(SQLException e){
                     System.err.println(e);
                 }
        }
 
 
 
}

Open in new window

Avatar of Mick Barry
Mick Barry
Flag of Australia image

have u created that database/table?
Avatar of KAMAU
KAMAU

ASKER

Yes i've created the database SimpleDBDemo2, i've created Table1 and using the sql tool (Runtime>Execute Command) i've successfully inserted 2 records. I've also successfully manged to query the database table using the sql query tool (Runtime>Execute Command). So i'm confident that the tables exist, and they have some sample data in them. Doing these operations using the SQL Query tool (See Runtime>Execute Command) is always successful. I have had no problems there.
However when i try executing the code above (Projects....>Main.java>Run File) that i get problems. Please see http://wiki.netbeans.org/wiki/view/GetStartedwithJavaDB for details on exactly how i created,connected and typed the code shown above
Try this:

ResultSet rs=stmt.executeQuery("Select * from SimpleDBDemo2.admin.Table1");
Avatar of KAMAU

ASKER

When i try  ResultSet rs=stmt.executeQuery("Select * from SimpleDBDemo2.admin.Table1"); i get a the following error message java.sql.SQLSyntaxErrorException: Syntax error: Encountered "." at line 1, column 34
Strange...

Have you tried the query with just the table name?

ResultSet rs=stmt.executeQuery("Select * from Table1");
Avatar of KAMAU

ASKER

When i try  ResultSet rs=stmt.executeQuery("Select * from Table1"); i get a the following error message java.sql.SQLSyntaxErrorException: Table/View 'TABLE1' does not exist. Just so you know i've tried various combinations none work. I would recommend creating a SimpleDBDemo2 database, pasting my code in a Main.java class file in your netbeans environment. And seeing if you get the same kind of error. It takes about 25mins to do it. Please see http://wiki.netbeans.org/wiki/view/GetStartedwithJavaDB for details on exactly how. I'd like to get pointers on what i'm doing wrong. I'm really trying to avoid guess work. If you've tired my code please help me identify my error.
What is this admin element?
The table is Table1 and the database is SimpleDBDemo2 why is admin involved? Are you trying to pass a username to the table?

The statement should be "Select * from Table1" since the connection already identifies the database.
But you are getting an error. Are you sure you are not mixing up an L with a one at the end of the table name either in the database or the code? Could be something as simple as that.
Avatar of KAMAU

ASKER

Well this is what i've gathered so far. ADMIN1 is the schema and Table1 is the table i want to connect to, Why do i require the Schema? I don't really know (it was in the example). Maybe its a quirk of JavaDB. also if you use SimpleDBDemo.Table1 it complains that it cannot identify the Schema, If you look in Netbeans.....Services Side bar(Press "Ctrl + 5" to bring up the "Services" side-bar in runtime) you will see the database Schema, URL and other details.
Ok - sorry I don't have the time to try to duplicate this right now, but just be sure you are matching names correctly - you just mentioned ADMIN1 while in the code you have ADMIN so if the last comment has the correct name then you are missing the 1 after admin in your code.

I will try and take a look at it later. Having never used JavaDB the construct seems strange. Hope you get this solved, this might just be one one of those things which make me either run away from or to JavaDB as an option. :)
Avatar of KAMAU

ASKER

Hello all, after much searching i'v found the solution
ResultSet rs=stmt.executeQuery("Select * from \"USER1\".\"Workers\"");
This works. I have no clue as to why. But it seems to work. If anyone has any idea why this works and ResultSet rs=stmt.executeQuery("Select * from admin.Table1"); fails i'd appreciate knowing.
ASKER CERTIFIED SOLUTION
Avatar of Computer101
Computer101
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial