0

Hei, im trying to connect to h database, via my java program but having problems with my driver issue. I am using ATOM editor not Eclipse or NetBeans!! How can I run my java program via ATOM editor?? I know that i need to include the HSQL JDBC driver in my class path but how can i do that? Here is my code:

import java.sql.Connection;
import java.sql.DriverManager;
public class ConnectDatabase {
public static void main(String[] args) {
  Connection con = null;

  try {
     //Registering the HSQLDB JDBC driver
     Class.forName("org.hsqldb.jdbc.JDBCDriver");
     //Creating the connection with HSQLDB

     con = DriverManager.getConnection("jdbc:hsqldb:mem:.", "SA", "");
     if (con!= null){
        System.out.println("Connection created successfully");

     }else{
        System.out.println("Problem with creating connection");
     }

  }  catch (Exception e) {
     e.printStackTrace(System.out);
  }
}
}
idleberg
  • 12,634
  • 7
  • 43
  • 70

1 Answers1

0

You need to add hsqldb jar to classpath, in this case you can copy it to folder where your Java class is located, then you need to compile it with -cp flag for example javac -cp ./hsqldb.jar ConnectDatabase.java and run the program with java -cp ".:./hsqldb.jar" ConnectDatabase in case when you have Linux or java -cp ".;./hsqldb.jar" ConnectDatabase on Windows

matt
  • 118
  • 1
  • 9
  • Thank You so much. You made my day :) I had my jar file located to the folder but was compiling not right and couldn't find an answer on internett. – Viktorija Blaziene Sep 29 '18 at 17:14
  • @ViktorijaBlaziene Awesome :) if your problem is resolved I'd suggest you mark it as answered. – matt Sep 29 '18 at 18:43