I'm using java JDBC to connect to SQLite on my Mac. The official tutorial is using windows. However I'm using a Mac.
Below is the command I ran in the terminal at connect
folder. This the command provided in the tutorial. https://www.sqlitetutorial.net/sqlite-java/sqlite-jdbc-driver/
java -classpath ".;sqlite-jdbc-3.27.2.1.jar" net.sqlitetutorial.Connect
Below is my file hierarchy.
╭─ ~/sqlite ········································at 17:27:22
╰─ tree
.
├── db
│ └── chinook.db
└── java
└── connect
├── net
│ └── sqlitetutorial
│ ├── Connect.class
│ └── Connect.java
└── sqlite-jdbc-3.27.2.1.jar
5 directories, 4 files
Blow is the Connect.java
the tutorial provided, I only changeString url =
to my own path in my computer.
package net.sqlitetutorial;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
/**
*
* @author sqlitetutorial.net
*/
public class Connect {
/**
* Connect to a sample database
*/
public static void connect() {
Connection conn = null;
try {
// db parameters
String url = "jdbc:sqlite:/Users/anasiangangster/sqlite/db/chinook.db";
// create a connection to the database
conn = DriverManager.getConnection(url);
System.out.println("Connection to SQLite has been established.");
} catch (SQLException e) {
System.out.println(e.getMessage());
} finally {
try {
if (conn != null) {
conn.close();
}
} catch (SQLException ex) {
System.out.println(ex.getMessage());
}
}
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
connect();
}
}
The original from the tutorial
String url = "jdbc:sqlite:C:/sqlite/db/chinook.db";
Anyway, when I ran the command(I provided in front) at connect
folder.
I get this error message.
Error: Could not find or load main class net.sqlitetutorial.Connect
Even though, I follow the troubleshooting method the tutorial provided. I'm not be able to solve it. Please help me if can. Thank you so much.