jQuery in Action, 2nd edition*
The moose likes JSP and the fly likes Connecting to a database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Connecting to a database" Watch "Connecting to a database" New topic
Author

Connecting to a database

Eman Adenola
Greenhorn

Joined: Apr 03, 2011
Posts: 27
Hello, I'm a new member, yep you guessed it.
I really need help understanding some concepts but I will like to take it one at a time.
The major problem is connecting to a database. The pdfs I got are useless..my lecturers' note pointless..
I am using the <sql:dataSource> tag to connect to a database...but the problem is i don't understand the attributes..

the driver attribute, from what I could glean helps the database to understand the java code..so the java code is translated into the database language in order to understand and process it.
What i don't understand is..where can I find the correct driver to use? How do I know if it is the correct one to use..every tutorial as a different one I want to go crazy..
The same thing with the other url tag..apparent it is the url for where the database is located.
Since I am using Access how can I find the url of the database.
I have seen many rude comments about how Access is bad and everything..don't have a go at the student please :O..its for assignment


That is the driver in my lecturers notes..so I am using that..but i am not sure what url to use for the access.
I went to the datasource option and created a DataSource called access..But how do I link it to the Access database?
Please help a lost JSP programmer.
Thanks
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1016
Damnit you already stole what I was going to say

Don't code SQL into a JSP page.
Don't use the JDBC-ODBC driver
Don't use Access :-)

However, if you have to because of whatever draconian limitations are put on you by your environment, you have to.
Its been a while since I did this so my memory might be a little rusty, but:

Googling took me to these pages which refreshed my memory a bit. I would suggest checking 'em out.

http://www.herongyang.com/JDBC/JDBC-ODBC-MS-Access.html
http://www.devasp.com/samples/dsn_access.asp.

How do you link it to the Access database?
Via the DataSources(ODBC) control panel in windows.
You set up the DSN to point to your specific access database .mdb file.
Make sure you create a SYSTEM DSN, and not a user DSN.

Your URL from java then just becomes jdbc:odbc:[insert_name_of_DSN_here]
so jdbc:odbc:access would be correct.

Eman Adenola
Greenhorn

Joined: Apr 03, 2011
Posts: 27
I got it to work, that was the problem I was setting it in User DSN.
Cheers.
Sorry I stole your thunder ;)...Yeah considering that our lecturers themselves told us last year not to use Access, its a hypocritical that we have to use it now..Ah well, it is for an assignment.

Can you explain what a data source is exactly..Is it like the name for a connection to a database or something. The explanations aren't quite clear.
And is it possible to have multiple databases/tables to a datasource. I tried and it always created a new datasource :S

Thanks for help
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Connecting to a database
 
Similar Threads
BMP, Jboss, and mysql configuring
Hibernate in Netbeans 6.9.1
how to retrieve data from postgresql using odbc driver
Netbeans and MS Access
Register 2 DB drivers for the same url