Any comments i could add to this? package attendance; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.sql.Statement; public class SqliteDB { Connection conn = null; Statement stmt = null; public SqliteDB() throws ClassNotFoundException { //try to connect with db try { Class.forName("org.sqlite.JDBC"); // db parameters String url = "jdbc:sqlite:C:/sqlite/db/attendance.db"; // create a connection to the database conn = DriverManager.getConnection(url); System.out.println("Connection to SQLite has been established."); } catch (SQLException e) { System.out.println(e.getMessage()); } } public void executeQuery(String query) { try { this.stmt = conn.createStatement(); stmt.execute(query); }catch (Exception e) { System.out.println(e); } } public void closeConnection() { try { this.conn.close(); }catch( Exception e) { System.out.println(e); } } }
Any comments i could add to this?
package attendance;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class SqliteDB {
Connection conn = null;
Statement stmt = null;
public SqliteDB() throws ClassNotFoundException {
//try to connect with db
try {
Class.forName("org.sqlite.JDBC");
// db parameters
String url = "jdbc:sqlite:C:/sqlite/db/attendance.db";
// create a connection to the
conn = DriverManager.getConnection(url);
System.out.println("Connection to SQLite has been established.");
} catch (SQLException e) {
System.out.println(e.getMessage());
}
}
public void executeQuery(String query) {
try {
this.stmt = conn.createStatement();
stmt.execute(query);
}catch (Exception e) {
System.out.println(e);
}
}
public void closeConnection() {
try {
this.conn.close();
}catch( Exception e) {
System.out.println(e);
}
}
}
Step by step
Solved in 2 steps