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.

natch

Beginner

  • "natch" started this thread

Posts: 11

Date of registration: Jul 27th 2009

  • Send private message

1

Wednesday, September 16th 2009, 7:14pm

how to connect to a database? MDB/SQL

MDB
how to access a database MDB?
How to send and receive data?

SQL
how to access a database SQL?
How to send and receive data?

* I amateur programming, if possible have to be a simple code

A1880

Intermediate

  • "A1880" is male

Posts: 500

Date of registration: Jan 1st 2009

Location: Hanover, Germany

Occupation: Software Engineer

Hobbies: Hilbert Curves

  • Send private message

2

Wednesday, September 16th 2009, 9:28pm

Hi,
you might consider using the search facility of this forum. "database" yields 58 hits at the moment.

Greetings!

A1880

natch

Beginner

  • "natch" started this thread

Posts: 11

Date of registration: Jul 27th 2009

  • Send private message

3

Thursday, September 17th 2009, 2:14am

the link is not available

Quoted

The link you are trying to reach is no longer available or is invalid.


just want a small example to give in to the database and store data on it ...

This post has been edited 2 times, last edit by "natch" (Sep 17th 2009, 2:58am)


  • "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

4

Thursday, September 17th 2009, 12:47pm

Hello natch,

no problem, here is a description how to connect to an existing MDB and to receive data. If you want to send data, use the command executeUpdate, with the SQL command INSERT, UPDATE or DELETE.

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

natch

Beginner

  • "natch" started this thread

Posts: 11

Date of registration: Jul 27th 2009

  • Send private message

5

Thursday, September 17th 2009, 10:38pm

I've been watching the forum I found a topic to talk about how to access the MDB, but as I am still learning to program, I did not understand the code, I just wanted an example of how to send data to a database, can post an example of the code?

  • "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

6

Saturday, September 19th 2009, 12:08am

Hello natch,

here is an example:

Jabaco Source

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
Dim Con As java#sql#Connection
  Dim Order As java#sql#Statement
  Dim Data As ResultSet

  'Load the JDBC-ODBC driver
    Class.forName "sun.jdbc.odbc.JdbcOdbcDriver"

  'Create connection to the database test
    Set Con = java#sql#DriverManager.getConnection("jdbc:odbc:test")

  'Create statement
    Set Order = Con.createStatement

  'Create a table
    Order.executeUpdate("CREATE TABLE employee(Name char(25));")
    
  'Insert records - send data
    Order.executeUpdate("INSERT INTO employee VALUES('Schnell, Stefan');")
    Order.executeUpdate("INSERT INTO employee VALUES('Frog, Kermit');")

  'Execute a query - receive data
    Set Data = Order.executeQuery("SELECT * FROM employee;")

  'Print the result
    Do While Data.next()
      java#lang#system.out.println(Data.getString("Name"))
    Loop
  
  'Close the connection
    Con.close


Easy, isn't it ;)

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

sparkythex

Beginner

Posts: 3

Date of registration: Jan 26th 2011

  • Send private message

7

Wednesday, January 26th 2011, 4:06am

more database info

I have some questiions on this.
here is an example:

Jabaco Source

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
Dim Con As java#sql#Connection
  Dim Order As java#sql#Statement
  Dim Data As ResultSet

  'Load the JDBC-ODBC driver
    Class.forName "sun.jdbc.odbc.JdbcOdbcDriver"

  'Create connection to the database test
    Set Con = java#sql#DriverManager.getConnection("jdbc:odbc:test")

  'Create statement
    Set Order = Con.createStatement

  'Create a table
    Order.executeUpdate("CREATE TABLE employee(Name char(25));")
    
  'Insert records - send data
    Order.executeUpdate("INSERT INTO employee VALUES('Schnell, Stefan');")
    Order.executeUpdate("INSERT INTO employee VALUES('Frog, Kermit');")

  'Execute a query - receive data
    Set Data = Order.executeQuery("SELECT * FROM employee;")

  'Print the result
    Do While Data.next()
      java#lang#system.out.println(Data.getString("Name"))
    Loop
  
  'Close the connection
    Con.close

Cheers
Stefan
SORRY TO SHOW UP WITH A LIST, ALL in ONE POST!!!
I have several questions on this.

1. ;( Were does this code go?
Is it in the Form_Load()?

2. ;( I am assuming this is tied to "database" control dialog, correct? I have one on my form just in case, also the CommonDialog too.

3. I remember with VB6 there was an "BindingNavigator" (well that is what it is called in .net'10;; it may have been the atoddb control. or dbnavigator)
does jabaco have anything like that or do have to make my own start , previous, next, end, buttons?

4. ;( How can I make a Connect (open) button so that I can change the database in use?
4a. ;( ) Along with this how can i make it so that it remembers the last database?
4b.;( ) As more explanation on this,…. Want the app to do is remember what was the last database used, but also to allow for it to be changed, then remeber the new one and not the old one? (a recent activity might be nice though.)
4d.) ;( on connecting or opening is there a way it can make a new DB with table if one doesn't exist?
?( here is why i am asking. I want to make a app that will allow me to be a content management system for an online web comic. all the files will be local to the pc but i want it to track & sort the indiviual updates in to a database, so that they can be tracked & updated. when done they just export data to html code. I sort of have this in another code but it was to basic to do a database so once you add in the days info it you can't ever pull it back out.
here is a sample of what the database structure will look like .
(**note image is of excell just because that was easiest way to do layout.)[img]http://tigabyte.com/forums/download/file.php?id=4[/img]example : I plan to do it like chapters so like book one would be comicDB1 & book two would then be something like comicDB2, and so on. basiclly each book would be its own database.
I really don't care what database style is used, I just need to be more or less universal or specific to app so that it will work anywhere.
If it matters i would need one record to hold at least 500 characters of text, or more.
I have some content management website already that use the sql on the host. I want to move away from that.
actually I already have. I have as you can see in the screen shot set it up to all work of html.
for aditional example, if you want to look at the html code you can view my site.
......http://irongun.50webs.com/
you can barely tell the difference between the above site that is html from this one below that is host database driven.
......http://comic247.prophp.org/archive/archi…e.php?comicID=1

also if it is helpful here is a screen shot of my app so you can see how the interface breaks down.
but this doesn't have a database opt.
[img]http://tigabyte.com/forums/download/file.php?id=3[/img]

5.;( How is it that I load a record in to like a text area, if data exist? Like when then hit the “previous”
....I think this is called binding in vb.

This post has been edited 5 times, last edit by "sparkythex" (Jan 26th 2011, 5:59am)


A1880

Intermediate

  • "A1880" is male

Posts: 500

Date of registration: Jan 1st 2009

Location: Hanover, Germany

Occupation: Software Engineer

Hobbies: Hilbert Curves

  • Send private message

8

Wednesday, January 26th 2011, 9:37am

Quoted

SORRY TO SHOW UP WITH A LIST, ALL in ONE POST!!!
I have several questions on this.

Yes, your questions are a bit inconvient to answer.

Quoted

1. ;( Were does this code go?
Is it in the Form_Load()?

You can include it in any function or method you want.
In Form_Load usually only the one-time actions without direct visibility are placed or called.

Quoted

2. ;( I am assuming this is tied to "database" control dialog, correct?

No, the code is independent of a DataBase control. It directly accesses the database on its own.

Quoted

3. I remember with VB6 there was an "BindingNavigator"

There is nothing like a BindingNavigator in Jabaco

Quoted

4. ;( How can I make a Connect (open) button so that I can change the database in use?

Your code has to close the current connection and open a new connection.

Quoted

4a. ;( ) Along with this how can i make it so that it remembers the last database?

Store the connection in a module variable (i.e. a non-local variable which lives longer than a method/function call)

Quoted

4b.;( ) As more explanation on this,…. Want the app to do is remember what was the last database used, but also to allow for it to be changed, then remeber the new one and not the old one? (a recent activity might be nice though.)

Not quite sure what you mean, but you could keep an array or list of database connections

Quoted

4d.) ;( on connecting or opening is there a way it can make a new DB with table if one doesn't exist?

That depends on the database system you are using.
You could query the database for existance of the table first and issue a "create table" on demand.

Quoted

I really don't care what database style is used, I just need to be more or less universal or specific to app so that it will work anywhere.

Some databases are lighter and simpler than others. Some cost money, some are for free.
If you want to roll-out your database to other users you have to consider the prerequisites on the user side.

Quoted

5.;( How is it that I load a record in to like a text area, if data exist? Like when then hit the “previous”
....I think this is called binding in vb.

SQL select returns a recordset which can be looped though.
If the recordset is empty, your query has not matched any records.
You application has to make sure that you properly handle the cases Null) One) Many) hits.

Happy reading and experimenting!

A1880

sparkythex

Beginner

Posts: 3

Date of registration: Jan 26th 2011

  • Send private message

9

Wednesday, January 26th 2011, 9:37pm

Happy reading and experimenting!

A1880
amazing you managed to answer all questions with out providing any solution.
thanks.!!!!

sparkythex

Beginner

Posts: 3

Date of registration: Jan 26th 2011

  • Send private message

10

Friday, January 28th 2011, 3:59am

Lets try this again.
is there a example of CODE for the different opts of database management.
It doesn't have to be new answer, it can be link to older post. I just can't find how.

I need to see:
1. CODE how to switch between multi-databases ; using open button?

2. CODE how to hit button "update" to update what is in a multilinetext box or rtf box to a particular record field.?

3. CODE how to read from a particular record field into a multiline textbox from hitting button "next" & "previous"?

4. CODE to use an .INI file (UNLESS there is other way to have info save settings with out ini, that is the only way i know.)to remember what was last database used - as in i have closed the program & reopened it. I want to use the last one i was using from last time?

5. CODE how to delete a record (obviously it will be the one active in my text box.).

6. CODE How to insert in the middle, a new record? (example: i want to insert new in between #3 & #4)

A1880

Intermediate

  • "A1880" is male

Posts: 500

Date of registration: Jan 1st 2009

Location: Hanover, Germany

Occupation: Software Engineer

Hobbies: Hilbert Curves

  • Send private message

11

Friday, January 28th 2011, 11:46am

As far as I know, such code samples are not available in this forum. Sorry!
But obviously, the Internet is full of code snippets written in Java.
It takes a couple of minutes to re-write them in Jabaco.

Copy & paste programming has its limits.
Unless you understand what you are doing, you'll end in problems.

I am not fully sure about your aim.
But if you plan to implement an application with mutliple databases and multiple users,
you have to make sure to have a proper concept for locking.
Otherwise there will be conflicting accesses by concurrent users.

I hope for your understanding that I can't provide more help here.

Greetings

A1880

nificucund

Beginner

Posts: 1

Date of registration: Jan 28th 2011

  • Send private message

12

Friday, January 28th 2011, 5:41pm

I don't have code (yet), sorry.

It looks like there is no way (yet) to bind a database and/or its recordset to a form or control, at least not with point and click on the part of the programmer in the IDE. That doesn't mean that it is impossible for the run-time program to present a form to the user with the usual next/previous, open/close, edit record, etc. It just takes some coding "behind the scenes".

For example, once you have implemented the code to get a recordset (see above), and have one "row", take the value for each field and assign it to a field in your form. If the user clicks on "next", have the code go to the next record in the recordset and populate those values into the form, and so forth. If the user clicks "close", the program runs code that closes the connection to the database (example of that code is above).

There are lots of ways to do it. For example, if you know there won't be many rows in your recordset (suppose you use LIMIT 1, for example) you could load the row(s) into an array and close the connection to the database, then present some values in the array to the user by putting them into appropriate places in the form. If the user makes changes, send the new values to a function that opens the connection to the database and executes the appropriate SQL statement, then closes the connection. (Not very efficient if you have lots of edits, but it's just an example.)

If you are going to allow the user to change the name of the database or connection, you wouldn't want to have the connection open already, so you wouldn't put the corresponding "open connection" code in Form_Load for the form that lets the user specify a different name. You might put that code in a On_Click event of a Button labeled "Open". Or you could put it into the Form_Load event of a second form for displaying a recordset. Depends on what you want to happen. Perhaps after opening the connection, you want to ask the user for a search term on a new form, then present the results to the user on yet a third form. Or maybe you ask the user for the search term, then go and open the connection and execute SQL to see if there are any matches, and present a form based on the result. Lots of ways to do it.

Rate this thread
WoltLab Burning Board