Started to implement the sqlite db connector.

This commit is contained in:
Servicepoint
2014-09-24 17:40:36 +02:00
parent 6fe900756a
commit 68220584a3
5 changed files with 113 additions and 0 deletions

View File

@@ -2,5 +2,7 @@
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="lib" path="lib/mysql-connector-java-5.1.32-bin.jar"/>
<classpathentry kind="lib" path="lib/sqlite-jdbc-3.7.2.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@@ -0,0 +1,21 @@
package de.katho.kBorrow;
import java.io.FileNotFoundException;
import java.sql.SQLException;
import java.sql.Statement;
import de.katho.kBorrow.db.*;
public class Main {
public static void main(String[] args) {
try {
SqliteConnector sqlite = new SqliteConnector("test.db");
} catch (FileNotFoundException | SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

View File

@@ -0,0 +1,5 @@
package de.katho.kBorrow.db;
public class SqlConnector {
}

View File

@@ -0,0 +1,42 @@
package de.katho.kBorrow.db;
import java.io.File;
import java.io.FileNotFoundException;
import java.sql.*;
/**
* @class sqliteConnector
* @author Servicepoint
*
* This class handles connections to a sqlite database.
*/
public class SqliteConnector {
private Connection connection;
private String dbHandle;
/**
* @param dbHandle This string contains the path to database file the connector has to use
* @throws FileNotFoundException, SQLException
*/
public SqliteConnector(String dbHandle) throws SQLException, FileNotFoundException {
this.dbHandle = dbHandle;
File f = new File(this.dbHandle);
if(!f.exists() || f.isDirectory()){
throw new FileNotFoundException("Provided database file \""+this.dbHandle+"\" not found.");
}
try {
Class.forName("org.sqlite.JDBC");
this.connection = DriverManager.getConnection("jdbc:sqlite:"+this.dbHandle);
Statement st = this.connection.createStatement();
st.executeUpdate("create table object (id integer, name string, comment string)");
}
catch (ClassNotFoundException e){
e.printStackTrace();
}
}
}

View File

@@ -0,0 +1,43 @@
package de.katho.kBorrow.gui;
import java.awt.EventQueue;
import javax.swing.JFrame;
public class MainWindow {
private JFrame frame;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
MainWindow window = new MainWindow();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public MainWindow() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}