0

I have this code:

     Public class DatabaseCon{


     private static Connection con;

     public static final String user = “user”;

    public static final String password = “password”;

    public static final String db =           “jdbc:derby://localhost:1527/testdb”;
      public static Connection getConnection()

     if (con == null)

    try
    {
    con = DriverManager. getConnection(db, user,   password);

     System. out.printin("created connection to " + db + " "+ user + “ “ + password);
     System. out.printin("the connection: " + con);
     System. out.print ("Current database: " +   con.getCatalog());
     DatabaseMetaData metaData = con.getMetaData();
     String[] types = {"TABLE"}:
     ResultSet resultSet = metaData. getTables (null,  null,
     "g'"', new String[]{"'TABLE"});
     ArrayList<String> tables = new ArrayList<String>();

     while(resultSet.next()){
     String tableName = resultSet.getString("TABLE NAME" )  ;
     tables. add (tableName);

    System. out.printin(tables);
     System. out.println("Tables are done!");

     }


     System.out.println("url: " + con.getMetaData ().getURL ());


      }

It outputs an error saying:

connection is null, creating connection! created connection to jdbc:derby://localhost:1527/testdb java java the connection: org.apache.derby.client.net.NetConnection@7b75baeb Current database: null== Tables Tables are done! url:jdbc:derby://localhost:1527/testdb getConnection is done!

java.sql. SQLSyntaxErrorException: Table/View 'PEOPLE' does not exist.
at org.apache.derby.client.am.SQLExceptionFactory.getSQLException(SQLExceptionFactory.ji
at org.apache. derby.client.am.SqlException.getSQLException (SqlException. java: 325)
at org.apache.derby. client.am. ClientConnection.prepareStatement(ClientConnection.java:4.

If anyone could help please reply

Jim Mac
  • 9
  • 2
  • The error message mentions `PEOPlE` - did you mean to refer to `PEOPLE`? – andrewJames Jan 09 '22 at 01:57
  • Yes it refers to ‘PEOPLE’ table – Jim Mac Jan 09 '22 at 02:15
  • What happens if you change `PEOPlE` to `PEOPLE`? If that solves the problem, then great (assuming your table names are case-sensitive - I don't know if that applies with Derby). Otherwise, that will eliminate one possible cause. – andrewJames Jan 09 '22 at 13:46
  • Also, the code in the question looks odd - it uses curly quotes such as `user = “user”` - whereas the correct syntax requires regular quotes such as `user = "user"`. That's probably just a copy/paste issue. Did you copy/paste via MS-Word or similar? Regardless, the code in the question should accurately reflect the code you are actually using. – andrewJames Jan 09 '22 at 13:47
  • Yeah it’s a copy and paste issue, the compiler actually said ‘PEOPLE’ and it uses regular quotes. I used the notes app – Jim Mac Jan 09 '22 at 13:54
  • OK - understood, thank you. The code in the question should accurately reflect the code you are actually executing. Same applies to the error message. You can [edit] the question. This will help the community to avoid being distracted by things which turn out to be irrelevant. – andrewJames Jan 09 '22 at 14:03
  • It says “ Oops! Your answer couldn't be submitted because: It looks like your post is mostly code; please add some more details.” when I try to edit – Jim Mac Jan 09 '22 at 14:13
  • "Your answer..."? You should be trying to edit (improve) your existing question, not post an answer. – andrewJames Jan 09 '22 at 14:14
  • There are lots of reasons you might get "table does not exist"; here are some: https://stackoverflow.com/a/23051822/193453 – Bryan Pendleton Jan 10 '22 at 02:11

0 Answers0