• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to open ".mdb" file(access database) by java code

 
aminur rashid
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a .mdb(acces file ).I want to open this mdb file by java programme .This means that whenever i run my java code with the path of mdb specified in the code, the mdb file should open up .Can any one help me out how to do this?
Thanks
Amin
 
Bosun Bello
Ranch Hand
Posts: 1510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to use JDBC. There is a little bit of learning that you have to do if you've never used JDBC. You also have to set up your environment for your DSN. There is a JDBC tutorial with examples at Sun's site.
------------------
Bosun
SCJP for the Java� 2 Platform
 
Stanley Tan
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can also access it without a DSN using:
jdbc dbc:MS Access Database;DBQ="C:\\Somewhere\\DB.mdb"
If you are using Microsoft Office 97 then replace "MS Access Database" with "MS Access 97 Database". If it doesn't work, go to your Control Panel and click on ODBC. Replace "MS Access Database" with whatever is there.
HTH
 
Stanley Tan
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
BTW, how do you get rid of the :O ? is there a way to "escape" the smiley?
 
Daniel Walker
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a box at the foot of the "post reply" page, in the "options" section. Click it.
------------------
daniel.walker
***i fear that i am ordinary...
...just like everyone...***
 
Shubhrajit Chatterjee
Ranch Hand
Posts: 356
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by aminur rashid:
I have a .mdb(acces file ).I want to open this mdb file by java programme .This means that whenever i run my java code with the path of mdb specified in the code, the mdb file should open up .Can any one help me out how to do this?
Thanks
Amin

You have to follow these steps.
1. Create a system data source name using the odbc administrator of the windows machine you are using.
2. Load the sun.jdbc.odbc.JdbcOdbcDriver class(Since we are using JDBC type 1 connection)
3. Get a conection to the database
4. Create a statement object
5. Fire an SQL to obtain a resultset
6. Browse thru the resultset to obtain data and do your processing
7. Close the connection

------------------
Shubhrajit
 
Matthew Roth
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can java open an MS Access database without Access being installed on a computer?
The user will have to log in to my program with a password. I'm trying to figure out where the best place is to place the username and password. I thought I could place it into an Access database and then include that with the program when I distribute the program. I know a lot of people don't have Access.
I didn't think a text file would be the best place for username and passwords. Any suggestions would be appreciated. Thanks
 
Reuben Cleetus
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you can open an MS Access Database (*.mdb), without having Access itself installed on the computer. Remember, you're using JDBC to open the Database, which has nothing to do with Access.
Even if you choose to use JDBC DBC to get to your Access database, you still don't need Access installed.
Regards,
Reuben Cleetus.
 
Matthew Roth
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Reuben, I thought that would be the answer but I wasn't for sure.
Thanks again,
Matt
 
aminur rashid
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually what answer i was expecting when i started the thread is given below as the code.Actually i was not talking of making a conncetion to the access file but to open the access file as such from the directory itself..i was expecting this code which i got somewhere in the Forum itself....3 cheers for the forum
Thank U all for the valuable contribution.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic