Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class App
- {
- private static final String JDBC_DRIVER = "org.sqlite.JDBC";
- private static final String CONNECTION_STRING = "jdbc:sqlite:/tmp/testdb.db";
- public static void main( String[] args ) throws SQLException, ClassNotFoundException {
- SQLiteDataSource ds = new SQLiteDataSource();
- ds.setUrl("jdbc:sqlite:/tmp/data.db");
- DBI dbi = new DBI(ds);
- Handle h = dbi.open();
- h.execute("create table something (id integer primary key, name text)");
- h.execute("insert into something (id, name) values (?, ?)", 1, "Brian");
- String name = h.createQuery("select name from something where id = :id")
- .bind("id", 1)
- .map(StringMapper.FIRST)
- .first();
- System.out.println(name);
- h.close();
- }
- private static Connection connection(String driver, String connectionString) throws SQLException, ClassNotFoundException {
- return connection(driver, connectionString, "", "");
- }
- private static Connection connection(String driver, String connectionString, String username, String password) throws ClassNotFoundException, SQLException {
- Class.forName(driver);
- return DriverManager.getConnection(
- connectionString,
- username,
- password
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement