I've got a problem. I have a console application, which is working with SQLite db. User enters password in console, than my app encrypts it and I need to write hash to db. I'm compiling and lauching my app only in ubuntu terminal using javac and java commands, because I use Console object instance and its method readPassword() and can't lauch my app in intellij idea built-in terminal. And I get such exception every time my app trying to use db:
java.lang.ClassNotFoundException: org.sqlite.JDBC at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:264) at com.company.DBHelper.connect(DBHelper.java:12) at com.company.StringOperator.save(StringOperator.java:15) at com.company.PasswordHelper.start(PasswordHelper.java:30) at com.company.Main.main(Main.java:14)
Here's my class forworking with DB:
package com.company;
import java.sql.*;
class DBHelper {
private static Connection connection;
private static Statement statement;
static private final String tableName = "passwords";
static void connect() throws ClassNotFoundException, SQLException {
connection = null;
Class.forName("org.sqlite.JDBC");
connection = DriverManager.getConnection("jdbc:sqlite:password.db");
System.out.println("Connected");
}
static void createDB() throws ClassNotFoundException, SQLException
{
statement = connection.createStatement();
statement.execute("CREATE TABLE if not exists '" + tableName + "' ('id' INTEGER PRIMARY KEY AUTOINCREMENT, 'hash' text);");
System.out.println("Table was created or already exists");
}
static void writeToDB(String password) throws SQLException
{
String query = "INSERT INTO '" + tableName + "' ('hash') VALUES ('" + password + "');";
statement.execute(query);
System.out.println("Password was successfully added to DB");
}
static void close() throws SQLException
{
statement.close();
connection.close();
System.out.println("Connection is closed");
}
}
I'm pretty sure that this code is okay, 'cause I've tested it in another console application, with simple input of data (simply Scanner), so I lauched it in intelliJ built-in console. I just can't realise, how I need to compile it, maybe in some special way using javac or smth else. I have googled this question in a many ways, I have set different properties in intelliJ but it doesn't help.