#Region Project Attributes
#MainFormWidth: 600
#MainFormHeight: 600
#AdditionalJar: sqlite-jdbc-3.7.2.jar ' this is in libs folder of B4J (v5.50)
#End Region
Sub Process_Globals
Private fx As JFX
Private MainForm As Form
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
MainForm.Show
asJO(Me).RunMethod("connect",Null)
End Sub
'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
Return True
End Sub
Sub asJO(o As JavaObject) As JavaObject
Return o
End Sub
#if java
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public static void connect() throws ClassNotFoundException {
Connection conn = null;
try {
Class.forName("org.sqlite.JDBC"); // force classloader to load the sqllite driver
// db parameters
String url = "jdbc:sqlite:mydatabasefile.db";
// create a connection to the database
conn = DriverManager.getConnection(url);
System.out.println("Connected");
} catch (SQLException e) {
System.out.println(e.getMessage());
} finally {
try {
if (conn != null) {
conn.close();
System.out.println("Closing database");
}
} catch (SQLException ex) {
System.out.println(ex.getMessage());
}
}
}
#End If