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.

Ephestion

Beginner

  • "Ephestion" started this thread

Posts: 5

Date of registration: Jun 23rd 2009

  • Send private message

1

Tuesday, June 23rd 2009, 10:51am

How to read a MDB database?

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Public Sub cmdButton_Click()
'On Error Resume Next
Dim strSQL As String
Dim rSet As ResultSet
strSQL ="SELECT * FROM Test"

If Database1.ConnectMDB("C:\myMDB.mdb") Then
rSet = Database1.ExecuteStatement(strSQL)
rSet.getRow()
rSet.moveToCurrentRow
rSet.findColumn("Test1")
text1.Text = rSet.getString(1)'??????????????
End If

rset.close
End Sub


My fields are ID, Test1, Test2 in the table Test in the database myMDB.mdb.

All i want to know is how do i return a value from a specific field eg Row 1 Column 1 of ResultSet?

gabizzz

Beginner

  • "gabizzz" is male

Posts: 5

Date of registration: Jun 18th 2009

Location: Argentina

  • Send private message

2

Wednesday, June 24th 2009, 7:07pm

http://www.jabaco.de/board/35-datenbank-anbinden.html

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
Public Sub Command1_Click()
   ' DATABASE: myMDB.mdb
   '  |_ TABLE: test
   '	|_ FIELD 1: id
   '	|_ FIELD 2: test1
   '	|_ FIELD 3: test2
   
   Dim res As ResultSet
   Database1.ConnectMDB("C:\myMDB.MDB")
   
   Dim rows As Integer = 0
   JBGrid1.Cols = 3   
   JBGrid1.Header(0) = "ID"
   JBGrid1.Header(1) = "Test1"
   JBGrid1.Header(2) = "Test2"
   
   res = Database1.ExecuteStatement("SELECT * FROM test")
   Do While res.next
  	JBGrid1.TextMatrix(res.getRow() - 1, 0) = res.getString("id")
  	JBGrid1.TextMatrix(res.getRow() - 1, 1) = res.getString("test1")
  	JBGrid1.TextMatrix(res.getRow() - 1, 2) = res.getString("test2")
  	rows = rows + 1
  	JBGrid1.Rows = rows
   Loop
End Sub

  • "StefanSchnell" is male

Posts: 102

Date of registration: Mar 13th 2009

Location: Oberirsen - Germany

Occupation: Senior Software Engineer

Hobbies: Programming aund Photography

  • Send private message

3

Wednesday, June 24th 2009, 10:45pm

Hello Ephestion,
welcome at Jabaco.
Here is another solution with the JDBC-ODBC-Bridge:

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Dim ds As sun#jdbc#odbc#ee#DataSource
Set ds = New sun#jdbc#odbc#ee#DataSource()
ds.setDatabaseName("Test")

Dim sta As java#sql#Statement
Set sta = ds.getConnection().createStatement()

Dim res As java#sql#ResultSet
Set res = sta.executeQuery("SELECT * FROM Test")

Do Until Not res.next()
  Debug.Print res.getString("Test1")
  Debug.Print res.getInt("Test2")
Loop

ds.getConnection().close()


But with this solution it is necessary to configure the database file in the ODBC configuration.

Cheers
Stefan
Visit my personal or commercial site
If you have questions or suggestions, write me an eMail or
meet me here

Ephestion

Beginner

  • "Ephestion" started this thread

Posts: 5

Date of registration: Jun 23rd 2009

  • Send private message

4

Friday, July 10th 2009, 3:22pm

I seem to be getting errors all the time: From what I gather the getString function always fails me. Also for some reason it will not allow me to use the line "Dim res as ResultSet".

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
34
Exception in thread "AWT-EventQueue-1" java.lang.Exception: CallByName 'getString' failed!
	at VBA.Interaction.CallByName(Interaction.java:182)
	at VBA.Interaction.CallByName(Interaction.java:180)
	at VBA.Interaction.CallByName(Interaction.java:171)
	at Form1.Command1_Click(Form1.jsrc:21)
	at Form1$CommandButton._Click(Form1.jsrc:27)
	at VB.CommandButton.actionPerformed(CommandButton.jsrc:96)
	at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
	at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
	at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
	at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
	at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:272)
	at java.awt.Component.processMouseEvent(Component.java:6216)
	at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
	at java.awt.Component.processEvent(Component.java:5981)
	at java.awt.Container.processEvent(Container.java:2041)
	at java.awt.Component.dispatchEventImpl(Component.java:4583)
	at java.awt.Container.dispatchEventImpl(Container.java:2099)
	at java.awt.Component.dispatchEvent(Component.java:4413)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4556)
	at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4220)
	at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4150)
	at java.awt.Container.dispatchEventImpl(Container.java:2085)
	at java.awt.Window.dispatchEventImpl(Window.java:2475)
	at java.awt.Component.dispatchEvent(Component.java:4413)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
	at VBA.JabacoEventQueque.dispatchEvent(JabacoEventQueque.java:20)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

  • "StefanSchnell" is male

Posts: 102

Date of registration: Mar 13th 2009

Location: Oberirsen - Germany

Occupation: Senior Software Engineer

Hobbies: Programming aund Photography

  • Send private message

5

Friday, July 10th 2009, 11:26pm

Hello Ephestion,
try the following:
Press F1 and select the node sql below java in the tree, press the accept button and execute the program again.

Do you add the test database to your ODBC configuration? Open control, select administration and select datasource (ODBC). You see the dialog ODBC datasource administrator and the tab User-DSN is active. In the user datasource you must see your database with the correct name - in my example Test. Look at the image in the attachment.

Hope it helps. Please let us know the solution.

Cheers
Stefan
StefanSchnell has attached the following image:
  • ODBC.jpg
Visit my personal or commercial site
If you have questions or suggestions, write me an eMail or
meet me here

Ephestion

Beginner

  • "Ephestion" started this thread

Posts: 5

Date of registration: Jun 23rd 2009

  • Send private message

6

Sunday, July 12th 2009, 10:26am

Ok im trying the non ODBC example but I updated the references and it seems to work now. The only problem I am having now is assigning values from the ResultSet into text boxes. I don't want the JGrid object because I want to build a GUI and prefer to have Text Boxes or Labels display the results.

Text1.Text = res.getString("id") or text1.Text = CSTR(res.getString("id")) doesnt work.

Rate this thread
WoltLab Burning Board