Results 1 to 10 of 10

Thread: connect to a local database?

  1. #1

    Thread Starter
    Hyperactive Member CaptainPinko's Avatar
    Join Date
    Jan 2001
    Location
    London, Ontario, Canada
    Posts
    332

    Question connect to a local database?

    how do you connect to a local database? all the JDBC seems to assume that you have some dedicated query server and does not address the deal the simple (and prob most common) issue: of accesing a local database!?!

    any help will appreciated, THNX
    "There are only two things that are infinite. The universe and human stupidity... and the universe I'm not sure about." - Einstein

    If you are programming in Java use www.NetBeans.org

  2. #2
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    Well ...

    You can try setting up an ODBC connection to the local database.

    .
    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

  3. #3
    VirtuallyVB
    Guest

    Thumbs up

    After you create an ODBC Data Source (perhaps from Control Panel), you can use:

    import java.sql.*;
    ...
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con = DriverManager.getConnection("jdbc:odbc:Data_Source_Name", Login_name, password);
    ...
    where the bolded entries are what you created for the ODBC Data Source. If you use the Control Panel, Login_name and password are on the dialog you get to from the "Advanced..." button. These are default login/password settings.

    Hey honeybee or anybody,
    How would you add other user logins/passwords for a specific database? I'm using Win98.

  4. #4
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    Well ...

    A simple solution would be to create a login screen of sorts, and then pick up the user name and password from there, and create the connection string dynamically. Anyways, since the Class.ForName loads the driver class dynamically, this should not pose any problems.

    While using this with ODBC, however, I am not sure if it will work. It would be analogous to a VB app trying to use a DSN connection and a DSN-less connection. In the latter case, there would be few problems, but in the earlier one, there would be a few.

    .
    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

  5. #5
    VirtuallyVB
    Guest

    Question

    For the multiple usernames/passwords, I mean "informing the database that these are valid users" (my language may be incorrect here). The control panel allowed setting a default account. I didn't see where to add new accounts.

    Is there an sql command to create accounts?

  6. #6

    Thread Starter
    Hyperactive Member CaptainPinko's Avatar
    Join Date
    Jan 2001
    Location
    London, Ontario, Canada
    Posts
    332
    isn't there anything as simple as the datacontrol in VB?
    like i would just pass the location of the datbase and the type of format it is in (eg. M$ Access) and then i could just query it w/ a method or two or something w/o all this ODBC schtuff? this isn't supposed to be fancy, just enough to make of those "address book" apps....
    "There are only two things that are infinite. The universe and human stupidity... and the universe I'm not sure about." - Einstein

    If you are programming in Java use www.NetBeans.org

  7. #7
    VirtuallyVB
    Guest
    OOooohhhh you want a VB control / JavaBean thingy.

    Well, back in the 90's, I remember playing with Java StudioTM Visual JavaTM to connect to a database.
    http://java.sun.com/features/1998/10/tools.html
    http://java.sun.com/features/1998/10.../tools/js1.gif

    I couldn't find the actual download today though.

    If you see the ODBC icon in your control panel, you should check it out. If you see the icon there and want step by step instructions, then let me know.

    I setup an MS Access database source with nothing in it; then wrote Java code to create tables and queries. Then I actually looked at it in Access.

    I was wondering if you could just make a new DB in Access then use Java, but you still need to make an ODBC link to it.

  8. #8

    Thread Starter
    Hyperactive Member CaptainPinko's Avatar
    Join Date
    Jan 2001
    Location
    London, Ontario, Canada
    Posts
    332
    <whimper>so there is nothing nice in the JDK that will elt me donsoemthing as simple as this?



    Code:
    Visual Basic 6: dtaInventory is a data control
    
    
    dtaInventory.DatabaseName = App.Path + "\clothes.mdb"
    "There are only two things that are infinite. The universe and human stupidity... and the universe I'm not sure about." - Einstein

    If you are programming in Java use www.NetBeans.org

  9. #9
    VirtuallyVB
    Guest

    Lightbulb There Should Be

    I don't recall fiddling with ODBC in Control Panel when I checked out JDatastore and Cloudscape (two different vendor's Java DB code).

    You might want to try Sun's Java forum:
    http://forum.java.sun.com/

    and specifically the JDBC forum:
    http://forum.java.sun.com/forum.jsp?forum=48

    There should be a way to do it through a (Java) program because if you want to distribute your app, you can't expect to manually use the control panel.

    A less elegant way would be to write a registry setting (probably re-inventing the wheel). Just a thought. I'm going to see if I can find out what the control panel odbc technique writes to the registry.

    Please post your solution here as "Resolved" when you fiond it.

  10. #10
    VirtuallyVB
    Guest
    I've reduced the question to:
    How do I write registry keys in Windows from Java?

    Because if you copy two keys, you will have access to a database.

    One sets the DSN, the other links the DSN to the path to the mdb file. Then you just need to copy an mdb file to that path.

    Heck, maybe you could just write the *.reg file and execute it from Java.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width