troubleshooting Question

JDBC Problem: Schema '...' does not exist

Avatar of UrosVidojevic
UrosVidojevicFlag for Serbia asked on
16 Comments1 Solution3595 ViewsLast Modified:
Hi Java Experts,

I'm currently learning some JDBC basics and experimenting with Derby db. Everything was going fine, until  I tried to create table from the following program:

import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.PreparedStatement;

import java.util.Properties;

public class SQLExample03 {
      final String driver = "org.apache.derby.jdbc.EmbeddedDriver";
      final String protocol = "jdbc:derby:";
      final String dbname = "CarsDB";

      public void work() {
            try {
                  Properties props = new Properties();
                  props.put("user", "sysdba");
                  props.put("password", "masterkey");
                  Connection c = DriverManager.getConnection(
                        protocol + dbname + ";create=true", props);

                  Statement s = c.createStatement();
                  s.execute("CREATE TABLE CARS(" +
                          "  CarID CHAR(4) PRIMARY KEY, " +
                          "  Name  CHAR(20) NOT NULL DEFAULT 'Unknown', " +
                          "  Cost  INT NOT NULL CHECK(Cost BETWEEN 1000 AND 100000))");

                  PreparedStatement ps = c.prepareStatement(
                        "INSERT INTO CARS VALUES (?,?,?)");

                  ps.setString(1, "0001");
                  ps.setString(2, "Ferrari");
                  ps.setInt(3, 100000);
                  ps.setString(1, "0002");
                  ps.setString(2, "Audi");
                  ps.setInt(3, 50000);

                  ps.setString(1, "0003");
                  ps.setString(2, "Ford");
                  ps.setInt(3, 80000);
                  ResultSet rs = s.executeQuery("SELECT * FROM Cars");
                  while ( {
                        System.out.println(rs.getString(1) + " | " +
                                       rs.getString(2) + " | " +

                  boolean gotSQLExc = false;
                  try {
                        DriverManager.getConnection(protocol + ";shutdown=true");
                  } catch (SQLException e) {
                        gotSQLExc = true;
                  if (!gotSQLExc) {
                        System.out.println("Database did not shut down normally");
                  } else {
                        System.out.println("Database shut down normally");
            } catch (Throwable e) {
                  System.out.println("Exception thrown: ");
                  if (e instanceof SQLException) {
                  } else {

      private static void printSQLError(SQLException e) {
            while (e != null) {
                  e = e.getNextException();

      public static void main(String[] args) {
            new SQLExample03().work();            

When I try to run it, i get this output.

Exception thrown:
java.sql.SQLSyntaxErrorException: Schema 'SYSDBA' does not exist

Very strange thing is that, when I comment lines in this program that create and update table CARS and replace them with for example:

s.execute("CREATE TABLE X(Y INT)");

Run program, and then:
* remove previous line
* uncomment previously commented lines
* run program again,
table CARS is created without any exceptions.

Also when I make simplier tables without key words DEFAULT, CHECK,... I don't get any exceptions.

I have tried for hours, to figure out what is the problem, but it simply doesn't make any sense to me.
Any ideas, what is wrong?

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Log in to continue reading
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform for $9.99/mo
View membership options
Unlock 1 Answer and 16 Comments.
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
The Value of Experts Exchange in My Daily IT Life

Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>


Owner of Outages.IO
Phoenix, Arizona, United States
Member Since 2016
Join a full scale community that combines the best parts of other tools into one platform.
Unlock 1 Answer and 16 Comments.
View membership options
“All of life is about relationships, and EE has made a virtual community a real community. It lifts everyone's boat.”
William Peck

Member since 2004