0

The setup of my app:

setup

and the error that is thrown:

error

Hello, I am pretty new to java and netbeans. I previously worked on Adobe Flash. I am having this problem where error of db or table not found is being thrown. If anybody could makeout anything from the screenshots attached, Please help me. I am trying to use the derby.jdbc.EmbeddedDriver here to store data.

Below is the entire code.

  package loginapp;
  import java.sql.Connection;
  import java.sql.DriverManager;
  import java.sql.ResultSet;
  import java.sql.ResultSetMetaData;
  import java.sql.Statement;

 public class Loginapp {

 public static void main(String[] args) {
    // TODO code application logic here
    try
    {
        chkLogin();
    }
    catch(Exception e){
       e.printStackTrace(); 
    }
}
private static void chkLogin() throws Exception{
    Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
    Connection conn = DriverManager.getConnection("jdbc:derby:testdb;create=true");
    Statement stmnt = conn.createStatement();
    ResultSet results = stmnt.executeQuery("select * from USERLOGIN");
    ResultSetMetaData rsmd = results.getMetaData();
    int numCols = rsmd.getColumnCount();
    for(int i=0;i<=numCols;i++)System.out.print(rsmd.getColumnLabel(i)+"\t\t");
}   
}

Have included derby.jar in my library and the "jdbc:derby:testdb;create=true [user1 on APP]" points to the db. Am able to update when I do it from the SQL window.

Thank you

u32i64
  • 2,384
  • 3
  • 22
  • 36
adbury
  • 37
  • 8
  • can you try just USERLOGIN instead of APP.USERLOGIN and let me know? – Chathura Buddhika Feb 26 '17 at 14:46
  • 2
    Dont provide your problem details as links to pictures. All of that is **text**, so edit your question and provide the relevant information *as text* within your question please. – GhostCat Feb 26 '17 at 14:50
  • Thank you very much for your reply. I tried what you asked. It throws the same error. java.sql.SQLSyntaxErrorException: Table/View 'USERLOGIN' does not exist. – adbury Feb 26 '17 at 14:52
  • @GhostCat I actually didnt have an Idea how to explain my problem.. So I used those Screen shots. Thank you. – adbury Feb 26 '17 at 14:55
  • @adbury, right click on Libraries, add "Java DB Driver" from there. It will add 3 jar files to your project. may be that's the problem. And please right click on the database connection, select "Properties". then show me that dialog. – Chathura Buddhika Feb 26 '17 at 15:49

1 Answers1

0

As explained here,

Three common reasons for "table does not exist" when you think you've already created the tables:

  1. You are connecting to a different database than you think you were connecting to, and since you specified "create=true" on the Connection URL, Derby quietly created a new empty database for you.
  2. You are using the "in-memory" configuration of Derby, which means that when the database is closed (or your application exits), all the contents of the database disappear.
  3. You are connecting to the database as a different user, and you aren't issuing the SET SCHEMA statement, so you are using the default schema name, which is based on your user name, and so the two schemas are different and have completely different tables, so the table you created doesn't seem to exist when you use the other schema.
Community
  • 1
  • 1
Chathura Buddhika
  • 2,067
  • 1
  • 21
  • 35