You are not logged in.

Dear visitor, welcome to Jabaco - Community. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

  • "hectorrodriguez" started this thread

Posts: 1

Date of registration: Jan 27th 2009

  • Send private message

1

Tuesday, January 27th 2009, 4:41am

Connect to MySQL database

How do I connect to a MySql database?
Hector Rodriguez

Manuel

Administrator

  • "Manuel" is male

Posts: 256

Date of registration: Jul 16th 2008

Location: Erlangen, Germany

Occupation: Software Developer

Hobbies: Jabaco, game theory, text-mining

  • Send private message

2

Tuesday, January 27th 2009, 9:55pm

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.

Connection-sample:

Jabaco Source

1
2
3
4
5
6
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
   Call Database1.Connect("jdbc:mysql://server:port/database", "username", "password")


You have to modify server, port, database, username and password. Short usage-sample:

Jabaco Source

1
2
3
4
5
Dim myRes As ResultSet 
   myRes = Database1.ExecuteStatement("SELECT * FROM users LIMIT 10")
   Call myRes.first 
   MsgBox myRes.getString(1)
   MsgBox myRes.getString("nickname")


Further information about JDBC: http://java.sun.com/products/jdbc/overview.html
Further information about MySQL with JDBC: http://dev.mysql.com/usingmysql/java/

Charlie

Beginner

Posts: 1

Date of registration: May 31st 2009

  • Send private message

3

Sunday, May 31st 2009, 9:30pm

Sorry but something is not clear...

I put a command button on a form and I wrote this:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Private 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
   Call Database1.Connect("jdbc:mysql://localhost/database", "username", "password")

End Sub

Public Sub Command1_Click()

Dim myRes  As ResultSet
   myRes = Database1.ExecuteStatement("SELECT * FROM dati LIMIT 100")
   Call myRes.first 
   MsgBox myRes.getString(1)
   MsgBox myRes.getString("Nome")

End Sub


but running it nothing appened.
I mean that the compiling is OK but the field of database is not showed.

These are the messages wrote after clicking the button:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
Listening for transport dt_shmem at address: Jabaco77248
Exception in thread "AWT-EventQueue-1" java.lang.NullPointerException
	at VB.DataBase.ExecuteStatement(DataBase.jsrc:35)
	at Form1.Command1_Click(Form1.jsrc:15)
	at Form1$CommandButton._Click(Form1.jsrc:20)
	at VB.CommandButton.actionPerformed(CommandButton.jsrc:98)
	at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
	at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
	at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
	at java.awt.Component.processMouseEvent(Unknown Source)
	at javax.swing.JComponent.processMouseEvent(Unknown Source)
	at java.awt.Component.processEvent(Unknown Source)
	at java.awt.Container.processEvent(Unknown Source)
	at java.awt.Component.dispatchEventImpl(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Window.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at VBA.JabacoEventQueque.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)


Whats my mistake?

  • "Fabricio Nicolau" is male

Posts: 1

Date of registration: Jun 13th 2011

Location: Vila Velha - ES - Brasil

Occupation: Consultor

Hobbies: Programação

  • Send private message

4

Monday, June 13th 2011, 4:53pm

I had this problem.
What i do?


Source code

1
	Java.sql.SQLException: Before start of result set	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:982)	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927)	at com.mysql.jdbc.ResultSetImpl.checkRowPos(ResultSetImpl.java:841)	at com.mysql.jdbc.ResultSetImpl.getStringInternal(ResultSetImpl.java:5650)	at com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java:5570)	at com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java:5610)	at MDIChild1.cmd1_Click(MDIChild1.jsrc:5)	at MDIChild1$CommandButton._Click(MDIChild1.jsrc:10)	at VB.CommandButton.actionPerformed(CommandButton.jsrc)	at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)	at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)	at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)	at javax.swing.DefaultButtonModel.setPressed(Unknown Source)	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)	at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)	at java.awt.Component.processMouseEvent(Unknown Source)	at javax.swing.JComponent.processMouseEvent(Unknown Source)	at java.awt.Component.processEvent(Unknown Source)	at java.awt.Container.processEvent(Unknown Source)	at java.awt.Component.dispatchEventImpl(Unknown Source)	at java.awt.Container.dispatchEventImpl(Unknown Source)	at java.awt.Component.dispatchEvent(Unknown Source)	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)	at java.awt.Container.dispatchEventImpl(Unknown Source)	at java.awt.Window.dispatchEventImpl(Unknown Source)	at java.awt.Component.dispatchEvent(Unknown Source)	at java.awt.EventQueue.dispatchEventImpl(Unknown Source)	at java.awt.EventQueue.access$000(Unknown Source)	at java.awt.EventQueue$1.run(Unknown Source)	at java.awt.EventQueue$1.run(Unknown Source)	at java.security.AccessController.doPrivileged(Native Method)	at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)	at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)	at java.awt.EventQueue$2.run(Unknown Source)	at java.awt.EventQueue$2.run(Unknown Source)	at java.security.AccessController.doPrivileged(Native Method)	at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)	at java.awt.EventQueue.dispatchEvent(Unknown Source)	at VBA.JabacoEventQueque.dispatchEvent(JabacoEventQueque.java:20)	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)	at java.awt.EventDispatchThread.run(Unknown Source)

This post has been edited 1 times, last edit by "Fabricio Nicolau" (Jun 13th 2011, 4:59pm)


Rate this thread
WoltLab Burning Board