Solved

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

Posted on 2007-11-16
12
3,417 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
  • 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
 

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Fibonacci challenge 11 84
json format text only 4 65
Running Jira on Raspberry PI 2? 3 130
get weblogic logged in user in java 2 42
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

758 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now