You are not logged in.

gabizzz

Beginner

  • "gabizzz" is male
  • "gabizzz" started this thread

Posts: 5

Date of registration: Jun 18th 2009

Location: Argentina

  • Send private message

1

Thursday, June 18th 2009, 6:55pm

Connect to MySQL Database without Database component

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

This post has been edited 1 times, last edit by "gabizzz" (Jun 19th 2009, 1:09pm)


Jason

Beginner

Posts: 6

Date of registration: Jul 15th 2009

  • Send private message

2

Monday, August 10th 2009, 1:30pm

Distribution of drivers.

Hi
I'm pretty new to both Java and VB (I'm a Delphi Developer).

I have recreated the example above and it works fine, but if i create/deploy my application as an applet, it cant find the driver.

I kind of understand why this is, since the applet is essentially being downloaded and then embedded in the browser, so it loses the context of the jdk/jre and cant see the driver, I was just wondering how you get around this and that the best practice policy is for distributing applets. I would not like to have to force all the users on my intranet to install the Java JConnector driver. If someone could point me at a post or a body of ducumentation dealing with this, Id appreciate it.

Thanks

Jason

Beginner

Posts: 6

Date of registration: Jul 15th 2009

  • Send private message

3

Wednesday, August 19th 2009, 8:35am

Solved

Just in case anyone is interested.
I solved this problem after finding and reading this :

http://www.ericgiguere.com/articles/depl…va-applets.html

The trick is to add the driver to the archive downloads in your HTML file.

Quoted

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>
Jabaco-Applet
</title>
</head>
<body>
<APPLET ARCHIVE="dbtest.jar,mysql-connector-java-5.1.8-bin.jar" CODE="Applet1.class" WIDTH="400" HEIGHT="300">
<PARAM NAME="Compiler" VALUE="Jabaco">
</APPLET>
</body>
</html>


Rate this thread
WoltLab Burning Board