Xojo Developer Conference
25/27th April 2018 in Denver.
MBS Xojo Conference
6/7th September 2018 in Munich, Germany.

MBS Xojo Plugin Tutorial Videos

JavaDatabase Source

Note: The function DesktopFolder is deprecated in Xojo. You can replace it with SpecialFolder.desktop.

Class App
Inherits Application
// Constants
Const kFileQuitShortcut = Ctrl+Q
Const kFileQuit = E&xit
Const kEditClear = &Delete

// Event implementations
Sub Open()
dim j as JavaDatabaseMBS
dim r as JavaRecordSetMBS
dim f as FolderItem

f=DesktopFolder.Child("mysql-connector-java-5.1.6-bin.jar")

j=new JavaDatabaseMBS(f,"com.mysql.jdbc.Driver")
j.Host="jdbc:mysql://localhost:3306"
j.UserName="root"
j.Password=""

if j.Connect then
MsgBox "connected"

'j.ExecuteSQL "CREATE DATABASE mytest"
'
'if j.Error then
'MsgBox j.ErrorString
'end if

j.ExecuteSQL "USE mytest"

'j.ExecuteSQL "CREATE TABLE mytable(test_id int, test_val char(15) not null, PRIMARY KEY (test_id))"
'
'if j.Error then
'MsgBox j.ErrorString
'end if

'j.ExecuteSQL "INSERT INTO mytable(test_id, test_val) VALUES(1,'One')"
'j.ExecuteSQL "INSERT INTO mytable(test_id, test_val) VALUES(2,'Two')"
'j.ExecuteSQL "INSERT INTO mytable(test_id, test_val) VALUES(3,'Three')"
'j.ExecuteSQL "INSERT INTO mytable(test_id, test_val) VALUES(4,'Four')"
'j.ExecuteSQL "INSERT INTO mytable(test_id, test_val) VALUES(5,'Five')"
'
'if j.Error then
'MsgBox j.ErrorString
'end if

r=j.SelectSQL("SELECT * from mytable",true)
if r<>Nil then
while r.NextRecord
MsgBox str(r.getInt("test_id"))+" "+r.getString("test_val")

'r.updateInt("test_id",10+r.getInt("test_id"))
'r.updateRow
wend
end if

if j.Error then
MsgBox j.ErrorString
end if
else
MsgBox "Failed to connect"+EndOfLine+j.ErrorString+EndOfLine+str(j.Errorcode)

end if
End Sub
End Class

Class Window1
Inherits Window
End Class


All movies




Links
MBS Xojo Plugins