The recommended way from the MySQL-website is connecting to the MySQL-Server through JDBC with the Connector/J-driver. MySQL Connector/J is a native Java driver that converts JDBC (Java Database Connectivity) calls into the network protocol used by the MySQL database.
The installation of this driver is very simple:
Download the driver and copy the included Jar-file (e.g. "mysql-connector-java-3.0.17-ga-bin.jar") to the "[...]\jre\lib\
ext"-folder in your current Java-installation.
The JDBC API is designed to make it possible for you to write a single Jabaco/Java program and to use it to manipulate the data in a variety of different SQL database servers without a requirement to modify and/or recompile the program.
|
Source code
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
Dim sql As Statement
Dim bd As Connection
Dim res As ResultSet
Public Sub Form_Load()
On Error Resume Next
Dim driver As Class
driver = Class.forName("com.mysql.jdbc.Driver")
If driver = Nothing Then MsgBox "Not found!"
On Error Goto 0
bd = DriverManager.getConnection("jdbc:mysql://hostname:port/databasename, username, password)
End Sub
Public Sub Command2_Click()
sql = bd.createStatement()
sql.executeQuerry("select * from tablename") 'can use executeUpdate !!
list1.Clear
Do While res.next
list1.AddItem (res.getString("nombre")+(", ")+res.getString("apellido")+(", ")+res.getString("id"))
Loop
End Sub
|