Java & SQLite & Windows: connect to SQLite database on windows

TrablaJava & SQLite & Windows: connect to SQLite database on windows


Solving:

1. Download and add to project sqlite-jdbc jar from here:
https://bitbucket.org/xerial/sqlite-jdbc/downloads


Java & SQLite & Windows: connect to SQLite database on windows - tutorial 1


Java & SQLite & Windows: connect to SQLite database on windows - tutorial 2


2. Example code:


....

Connection lvConnection = null;

// Connect to db
Class.forName("org.sqlite.JDBC");


lvConnection = DriverManager.getConnection( "jdbc:sqlite:C:/Users/Samurai/Desktop/my.db" );

lvConnection.setAutoCommit(false);


Statement lvStatement = lvConnection.createStatement();

String lvSql = " TYPE YOUR SQL HERE ";

lvStatement.executeUpdate(lvSql); // for INSERT , UPDATE , DELETE 

lvConnection.commit();

lvStatement.close();
lvConnection.close();

.....

No comments:

Post a Comment