Click to See Complete Forum and Search --> : connect to a local database?
CaptainPinko
Jun 1st, 2002, 12:49 AM
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
honeybee
Jun 3rd, 2002, 02:59 AM
You can try setting up an ODBC connection to the local database.
.
VirtuallyVB
Jun 3rd, 2002, 04:59 PM
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.
honeybee
Jun 4th, 2002, 03:30 AM
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.
.
VirtuallyVB
Jun 4th, 2002, 11:39 AM
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?
CaptainPinko
Jun 4th, 2002, 04:47 PM
:rolleyes: 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....
VirtuallyVB
Jun 4th, 2002, 06:40 PM
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/images/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.
CaptainPinko
Jun 5th, 2002, 04:43 PM
<whimper>so there is nothing nice in the JDK that will elt me donsoemthing as simple as this?
Visual Basic 6: dtaInventory is a data control
dtaInventory.DatabaseName = App.Path + "\clothes.mdb"
VirtuallyVB
Jun 6th, 2002, 11:14 AM
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.
VirtuallyVB
Jun 7th, 2002, 06:20 PM
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.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.