2015-01-06 17:14:16 +01:00
|
|
|
package com.minres.scviewer.database.sqlite.db;
|
2015-01-03 16:34:32 +01:00
|
|
|
|
|
|
|
import java.sql.Connection;
|
|
|
|
import java.sql.DriverManager;
|
|
|
|
import java.sql.PreparedStatement;
|
|
|
|
import java.sql.ResultSet;
|
|
|
|
import java.sql.SQLException;
|
|
|
|
import java.sql.Statement;
|
2015-01-10 00:23:46 +01:00
|
|
|
import java.util.HashMap;
|
2015-01-03 16:34:32 +01:00
|
|
|
|
|
|
|
public class SQLiteDatabase implements IDatabase {
|
|
|
|
|
|
|
|
protected String dbFileName;
|
|
|
|
|
2015-01-10 00:23:46 +01:00
|
|
|
protected HashMap<String, Object> props;
|
|
|
|
|
2015-01-03 16:34:32 +01:00
|
|
|
public SQLiteDatabase(String dbFileName) {
|
|
|
|
super();
|
|
|
|
this.dbFileName = dbFileName;
|
2015-01-10 00:23:46 +01:00
|
|
|
props = new HashMap<String, Object>();
|
2015-01-03 16:34:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Connection createConnection() throws SQLException {
|
|
|
|
// create a database connection and return it
|
|
|
|
return DriverManager.getConnection(getConnectionUrl() );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getConnectionUrl() {
|
|
|
|
// now we set up a set of fairly basic string variables to use in the body of the code proper
|
|
|
|
String sJdbc = "jdbc:sqlite";
|
|
|
|
String sDbUrl = sJdbc + ":" + dbFileName;
|
|
|
|
// which will produce a legitimate Url for SqlLite JDBC :
|
|
|
|
// jdbc:sqlite:hello.db
|
|
|
|
return sDbUrl;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void close(ResultSet resultSet, Statement statement, Connection connection) {
|
2015-01-09 11:58:14 +01:00
|
|
|
try {
|
2015-01-20 18:50:15 +01:00
|
|
|
if(resultSet!=null) resultSet.close();
|
|
|
|
if(statement!=null) statement.close();
|
|
|
|
if(connection!=null) connection.close();
|
2015-01-09 11:58:14 +01:00
|
|
|
} catch (SQLException e) {}
|
2015-01-03 16:34:32 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void close(PreparedStatement preparedStatement, Connection connection) {
|
2015-01-09 11:58:14 +01:00
|
|
|
try {
|
|
|
|
preparedStatement.close();
|
|
|
|
connection.close();
|
|
|
|
} catch (SQLException e) {}
|
2015-01-03 16:34:32 +01:00
|
|
|
}
|
|
|
|
|
2015-01-10 00:23:46 +01:00
|
|
|
@Override
|
|
|
|
public void setData(String name, Object value){
|
|
|
|
props.put(name, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Object getData(String name){
|
|
|
|
return props.get(name);
|
|
|
|
}
|
|
|
|
|
2015-01-03 16:34:32 +01:00
|
|
|
}
|