Derby database problems

KrazyKatzKrazyKatz London, UK
edited June 2015 in Java Beginners

Hi there guys, thanks for reading!!

Im trying to learn how to create derby databases and have completed a tutorial program fine, but have now hit a brick wall on a program of my own and was hoping for a little advice. I think its only a minor error but I really cant spot it!

The Output im getting is:

run:
Available drivers:
sun.jdbc.odbc.JdbcOdbcDriver@1aaa14a
org.apache.derby.jdbc.ClientDriver@c2a132

Table is created, but no content yet
DB contents:
Problem:java.sql.SQLNonTransientConnectionException: Connection authentication failure occurred. Reason: userid or password invalid.
Exception in thread "main" java.lang.NullPointerException
at rest.DataBaseCreator.showData(DataBaseCreator.java:121)
at rest.Main.main(Main.java:10)
Java Result: 1
BUILD SUCCESSFUL (total time: 1 second)

I originally thought that there was something wrong with my username/pass but that is all fine, and someone on another forum suggested the error may come from somewhere else at the beginning of my code, before the getConnection:

package rest;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Enumeration;
public class DataBaseCreator
{
Connection connection;
Statement statement;

public DataBaseCreator()
{
try
{
Class.forName("org.apache.derby.jdbc.ClientDriver");
}
catch (ClassNotFoundException cnfe)
{
System.err.println("Derby driver not found.");
}
try
{
System.out.println("Available drivers:");
Enumeration drivers = DriverManager.getDrivers();
while (drivers.hasMoreElements())
{
System.out.println(drivers.nextElement());
}
System.out.println();

     connection = DriverManager.getConnection
           ("jdbc:derby://localhost:1527/Rest;create=true;user=****;pass=****");

     statement = connection.createStatement();

And the Main.java I have is:

package rest;
public class Main {
public static void main(String[] args) {
DataBaseCreator table = new DataBaseCreator();
System.out.println("Table is created, but no content yet");
table.showData();
table.addData();
System.out.println("Table now populated with data");
table.showData();
}
}

In my DatabaseCreator, it the goes on to create the table, and the set and print the results, but im sure that part is fine, im pretty sure its somewhere around the drivers that im having issues??

Any advice would be gratefully received, as this is driving me crazy now!

Thanks!

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories