Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2007-11-16
12
Medium Priority
?
3,495 Views
Last Modified: 2008-08-27
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
Comment
Question by:KAMAU
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
  • 2
  • +2
12 Comments
 
LVL 92

Expert Comment

by:objects
ID: 20297316
have u created that database/table?
0
 

Author Comment

by:KAMAU
ID: 20297363
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
 
LVL 9

Expert Comment

by:brunoguimaraes
ID: 20297852
Try this:

ResultSet rs=stmt.executeQuery("Select * from SimpleDBDemo2.admin.Table1");
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:KAMAU
ID: 20298013
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
 
LVL 9

Expert Comment

by:brunoguimaraes
ID: 20298067
Strange...

Have you tried the query with just the table name?

ResultSet rs=stmt.executeQuery("Select * from Table1");
0
 

Author Comment

by:KAMAU
ID: 20298236
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
 
LVL 4

Expert Comment

by:pcumberbatch
ID: 20298528
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
 

Author Comment

by:KAMAU
ID: 20298660
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
 
LVL 4

Expert Comment

by:pcumberbatch
ID: 20299281
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
 

Author Comment

by:KAMAU
ID: 20299338
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
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 22329741
PAQed with points refunded (125)

Computer101
EE Admin
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This video teaches viewers about errors in exception handling.
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question