In my application I am using JDBC connection to the sqlite database, and here is a sample code that creates the database and creates a sample table in it.
public class Main {
public static void main(String[] args) {
try {
Class.forName("org.sqlite.JDBC");
Connection connection = DriverManager.getConnection("jdbc:sqlite:db.sqlite","admin","123");
Statement statement = connection.createStatement();
String query = "CREATE TABLE Users(ID INTEGER PRIMARY KEY AUTOINCREMENT," +
"Login TEXT, " +
"Password TEXT);";
statement.execute(query);
String query1 = "INSERT INTO Users(Login, Password) VALUES ('user1','password1')";
String query2 = "INSERT INTO Users(Login, Password) VALUES ('user2','password2')";
String query3 = "INSERT INTO Users(Login, Password) VALUES ('user3','password3')";
statement.addBatch(query1);
statement.addBatch(query2);
statement.addBatch(query3);
statement.executeBatch();
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
}
}
}
Now the question is, I can easily open my db file without typing any user or password info from outside, so where are the parameters I give to the DriverManager used and how to specify a password for the database?
As mentioned in a comment, in .Net I can do following when making a connection
using(SQLiteConnection con = new SQLiteConnection("Data Source=db.sqlite; Password=123;")
{
//code goes here
}
So what is the JDBC equivalent for that?