Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3523
  • Last Modified:

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

0
KAMAU
Asked:
KAMAU
  • 5
  • 2
  • 2
  • +2
1 Solution
 
objectsCommented:
have u created that database/table?
0
 
KAMAUAuthor Commented:
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
0
 
brunoguimaraesCommented:
Try this:

ResultSet rs=stmt.executeQuery("Select * from SimpleDBDemo2.admin.Table1");
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
KAMAUAuthor Commented:
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
0
 
brunoguimaraesCommented:
Strange...

Have you tried the query with just the table name?

ResultSet rs=stmt.executeQuery("Select * from Table1");
0
 
KAMAUAuthor Commented:
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.
0
 
pcumberbatchCommented:
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.
0
 
KAMAUAuthor Commented:
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.
0
 
pcumberbatchCommented:
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. :)
0
 
KAMAUAuthor Commented:
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.
0
 
Computer101Commented:
PAQed with points refunded (125)

Computer101
EE Admin
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 5
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now