### Connect using JDBC Overview

To connect to databases via JDBC, you need the JDBC Driver and JDBC URL Format.
General Information
Download the driver from the reference site.
Copy the driver to the additional libraries folder: Menu Tools > Configure Path > Additional Libraries
Add the driver(s) to the Project Attributes as #AdditionalJar.
Reference the jSQL Library in the B4J IDE Library Manager.
The driver version used in below information might not be the latest version. These are examples used.
Look here: http://docs.oracle.com/javase/tutorial/jdbc/ to learn more about JDBC.
List of JDBC Drivers:
http://www.databasedrivers.com/jdbc/
http://www.oracle.com/technetwork/java/index-136695.html
MYSQL DATABASE
Information & Download:
http://dev.mysql.com/downloads/connector/j/
http://dev.mysql.com/downloads/connector/j/5.0.html
http://dev.mysql.com/doc/connector-j/en/index.html
Additional Jar:
mysql-connector-java-5.1.28-bin.jar
Note: If newer versions avaibale, then change the version information accordingly.
JDBC Driver Class:
com.mysql.jdbc.Driver
JDBC URL Format:
jdbc:mysql://localhost/database?characterEncoding=utf8
See here:
http://dev.mysql.com/doc/connector-j/en/connector-j-reference-configuration-properties.html
Example Remote Connect and Select Records
'Connecting to a Remote MySQL Database with IP Address 192.168.0.16, database notes, user notesuser and password.
Private gSQL As SQL
'Connect to the database notes
Try
gSQL.Initialize("com.mysql.jdbc.Driver", "jdbc:mysql://192.168.0.16/notes?user=notesuser&password=YOURPASSWORD")
Catch
Log(LastException.Message)
Return
End Try
'Select the records from table notes. This table has only 1 field: note varchar(255)
Dim cursor As ResultSet
Dim sb As StringBuilder
sb.Initialize
Try
cursor = gSQL.ExecQuery ("SELECT * FROM notes")
Do While cursor.NextRow
For i = 0 To cursor.ColumnCount - 1
sb.Append(cursor.GetColumnName(i) & " = " & cursor.GetString2(i) & CRLF)
Next
Loop
Catch
Log("ERROR: " & LastException.Message)
End Try

Changed: , Category: MySQL, File: T6C223M1648.htm, ID: 1648