I'm currently attempting to figure out how to use a Derby database in java. So-far I've been reading through this (Java For Complete Beginners - Databases) tutorial and I'm kinda-sorta sure that I've done most of this right but I'm a bit stuck at the moment.
So-far my code looks like this:
import java.sql.*; public class DataBaseTest { public static void main(String args[]) { int id = 1; try { String host = "jdbc:derby://localhost:1527/Test Database"; String uName = "removedTheUsername"; String uPass = "removedThePassword"; Connection dbConnection = DriverManager.getConnection( host, uName, uPass); Statement statement = dbConnection.createStatement(); String sql = "SELECT * FROM TESTTABLE"; ResultSet resultSet = statement.executeQuery(sql); for(int i = 0; i < id; i++) { resultSet.next(); if(i == id) { System.out.println(resultSet.getInt(1) + " " + resultSet.getString(2) + " " +resultSet.getInt(3)); } } } catch(Exception e) { e.printStackTrace(); } } }
It's pretty mush just mashed together since I'm still figuring this all out. The error that I'm getting is:
run: java.sql.SQLSyntaxErrorException: Schema 'TYEEEEE1' does not exist at org.apache.derby.client.am.SQLExceptionFactory40.getSQLException(Unknown Source) at org.apache.derby.client.am.SqlException.getSQLException(Unknown Source) at org.apache.derby.client.am.Statement.executeQuery(Unknown Source) at DataBaseTest.main(DataBaseTest.java:19) Caused by: org.apache.derby.client.am.SqlException: Schema 'TYEEEEE1' does not exist at org.apache.derby.client.am.Statement.completeSqlca(Unknown Source) at org.apache.derby.client.net.NetStatementReply.parsePrepareError(Unknown Source) at org.apache.derby.client.net.NetStatementReply.parsePRPSQLSTTreply(Unknown Source) at org.apache.derby.client.net.NetStatementReply.readPrepareDescribeOutput(Unknown Source) at org.apache.derby.client.net.StatementReply.readPrepareDescribeOutput(Unknown Source) at org.apache.derby.client.net.NetStatement.readPrepareDescribeOutput_(Unknown Source) at org.apache.derby.client.am.Statement.readPrepareDescribeOutput(Unknown Source) at org.apache.derby.client.am.Statement.flowExecute(Unknown Source) at org.apache.derby.client.am.Statement.executeQueryX(Unknown Source) ... 2 more BUILD SUCCESSFUL (total time: 0 seconds)
The database is named 'Test Database' and the table I'm trying to access is called 'TESTTABLE'.
I've checked out line 19 where the first error says something is going wrong but I don't know enough about half of these statements to figure out what's going wrong. If anyone can see where I went wrong and explain how to fix it that would help!