Ok this problem has confused me, i will outline what the program does first before i tell you the issue i am having.
I have set up HSQLDB i have created a program which reads from my database.properties file and connects to the database.
I then use this connection to perform some SQL commands such as add, remove and update entries from a simple console menu. If i enter my connection details manually so the url, username, password and driver it connects fine. When doing it manually i have username and password both as "", so the value is null. It all works fine then, my menu works, i can add, delete, update and display my table. If however, i try and connect by directing my program to the details in my database.properties file which also has a blank username and password field i cannot connect, i get this error message.
Exception in thread "main" java.sql.SQLInvalidAuthorizationSpecException: invalid authorization specification - not found: SA
I wanted to see what values were being used to connect so i put a println in to display the username and password when entering my details manually and also from reading from the file.
So when i attempt to establish a connection it shows me this line first. They both display username=null and password= null but if i link to the database.properties file i get the error message mentioned above . . . .It doesn't make sense to me as if a password/username were required, why can i connect by manually setting these to "" in my connection program?
Below is the connection program, you can see in the getConnection method i have the username and password field set to "". To use the values read from the file i use username and password instead.
import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.io.FileInputStream; import java.io.IOException; import java.util.Properties; public class SimpleDataSource { private static String url; private static String username; private static String password; private static String driver; public static void init(String database) throws IOException, ClassNotFoundException { Properties props = new Properties(); FileInputStream in = new FileInputStream(database); props.load(in); driver = props.getProperty("jbdc.driver"); url = props.getProperty("jbdc.url"); username = props.getProperty("jbdc.username"); if(username == null) { username = ""; } password = props.getProperty("jbdc.password"); if(password == null) { password = ""; }; } public static Connection getConnection() throws SQLException { System.out.println("Username:" + username + "Password:" + password); return DriverManager.getConnection("jdbc:hsqldb:file:myHSQLDB", "", ""); } }
Problem is now solved, i failed to call the init method.