Example: /Java/JavaDatabase/JavaDatabase SQLite blob

Online Documentation   -   Statistics   -   FAQ   -   Plugin Parts (All, Dependencies)   -   Class hierarchy

New in Version 22.2 22.3 22.4 22.5 23.0 23.1 23.2 23.3 23.4 23.5 24.0 24.1

The list of the   topics,   classes,   interfaces,   controls,   modules,   global methods by category,   global methods by name,   screenshots,   licenses   and   examples.

Platforms to show: All Mac Windows Linux Cross-Platform

/Java/JavaDatabase/JavaDatabase SQLite blob


Required plugins for this example: MBS Java Plugin

You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Java/JavaDatabase/JavaDatabase SQLite blob

This example is the version from Sun, 9th Mar 2013.

Project "JavaDatabase SQLite blob.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
EventHandler Sub Open() dim j as JavaConnectionMBS dim d as JavaDatabaseMBS dim r as JavaResultSetMBS dim f as FolderItem=SpecialFolder.desktop.Child("sqlitejdbc-v056.jar") if not f.Exists then MsgBox "Missing sqlite connector classes!" Return end if if TargetLinux then // change path for your linux PC! JavaVMMBS.SetLibraryPath("/home/cs/jre1.6.0_05/lib/i386/client/libjvm.so") end if dim v as new JavaVMMBS(f) dim c as JavaClassMBS = v.FindClass("java/io/InputStream") break d=new JavaDatabaseMBS(v,"org.sqlite.JDBC") j=d.getConnection("jdbc:sqlite:/tmp/test.db") if j<>Nil then // call j.prepareStatement("CREATE DATABASE JunkDB").execute j.MyExecuteSQL "DROP TABLE myTable" j.MyExecuteSQL "CREATE TABLE myTable(test_id int, test_val blob, PRIMARY KEY (test_id))" j.MyExecuteSQL "INSERT INTO myTable(test_id, test_val) VALUES(1,'One')" j.MyExecuteSQL "INSERT INTO myTable(test_id, test_val) VALUES(2,'Two')" j.MyExecuteSQL "INSERT INTO myTable(test_id, test_val) VALUES(3,'Three')" j.MyExecuteSQL "INSERT INTO myTable(test_id, test_val) VALUES(4,'Four')" j.MyExecuteSQLwithPreparedStatement "INSERT INTO myTable(test_id, test_val) VALUES(5,'Five')" // check second entry r=j.MySelectSQLwithPreparedStatement("SELECT * from myTable") if r<>Nil then while r.NextRecord dim ips as JavaInputStreamMBS = r.getBinaryStream("test_val") dim a as integer = ips.available dim byteArray as JavaByteArrayMBS = v.NewByteArray(a) dim count as integer = ips.read(byteArray) dim mem as MemoryBlock = byteArray.Region(0, byteArray.Length) dim dstr as string = mem dstr = DefineEncoding(dstr, encodings.ASCII) MsgBox str(R.getInt("test_id"))+" "+dstr wend else MsgBox "r is nil" end if r=nil r=nil MsgBox "OK" quit else MsgBox "not connected" end if Exception e as JavaExceptionMBS MsgBox e.message+" errorcode: "+str(e.ErrorNumber) End EventHandler
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
Module JavaUtil
Sub ExecuteSQL(extends c as JavaConnectionMBS, sql as string) try dim s as JavaStatementMBS s=c.createStatement if s<>nil then call s.executeUpdate sql end if catch d as JavaExceptionMBS MsgBox d.message+" ErrorCode: "+str(d.errornumber) end try End Sub
Sub MyExecuteSQL(extends j as javaconnectionMBS, sql as string) try j.ExecuteSQL sql catch d as JavaExceptionMBS MsgBox d.message+" ErrorCode: "+str(d.errornumber) end try End Sub
Sub MyExecuteSQLwithPreparedStatement(extends j as javaconnectionMBS, sql as string) try dim p as JavaPreparedStatementMBS p=j.prepareStatement(sql) if p<>Nil then call p.execute end if catch d as JavaExceptionMBS MsgBox d.message+" ErrorCode: "+str(d.errornumber) end try End Sub
Function MySelectSQL(extends j as javaconnectionMBS, sql as string, editable as boolean=false) As JavaResultSetMBS try return j.SelectSQL(sql,editable) catch d as JavaExceptionMBS MsgBox d.message end try End Function
Function MySelectSQLwithPreparedStatement(extends j as javaconnectionMBS, sql as string, editable as boolean=false) As JavaResultSetMBS try dim p as JavaPreparedStatementMBS p=j.prepareStatement(sql) if p<>Nil then dim r as JavaResultSetMBS r=p.executeQuery r.Tag=p // keep a reference to the statement Return r end if catch d as JavaExceptionMBS MsgBox d.message end try End Function
Function SelectSQL(extends c as JavaConnectionMBS, sql as string, editable as boolean=false) As JavaResultSetMBS try dim mode as integer = c.CONCUR_READ_ONLY dim s as JavaStatementMBS s=c.createStatement(c.TYPE_FORWARD_ONLY, mode) if s<>nil then dim r as JavaResultSetMbs r=s.executeQuery(sql) if r<>Nil then // you need to keep the statement with the r.Tag=s Return r end if end if catch d as JavaExceptionMBS MsgBox d.message+" ErrorCode: "+str(d.errornumber) end try End Function
End Module
End Project

See also:

The items on this page are in the following plugins: MBS Java Plugin.


💬 Ask a question or report a problem