Started to implement the sqlite db connector.
This commit is contained in:
@@ -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>
|
||||
|
||||
21
src/de/katho/kBorrow/Main.java
Normal file
21
src/de/katho/kBorrow/Main.java
Normal 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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
5
src/de/katho/kBorrow/db/SqlConnector.java
Normal file
5
src/de/katho/kBorrow/db/SqlConnector.java
Normal file
@@ -0,0 +1,5 @@
|
||||
package de.katho.kBorrow.db;
|
||||
|
||||
public class SqlConnector {
|
||||
|
||||
}
|
||||
42
src/de/katho/kBorrow/db/SqliteConnector.java
Normal file
42
src/de/katho/kBorrow/db/SqliteConnector.java
Normal 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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
43
src/de/katho/kBorrow/gui/MainWindow.java
Normal file
43
src/de/katho/kBorrow/gui/MainWindow.java
Normal 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);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user