aspose file tools*
The moose likes JDBC and the fly likes DB-newbie Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "DB-newbie" Watch "DB-newbie" New topic
Author

DB-newbie

Martin Schneider
Ranch Hand

Joined: May 16, 2002
Posts: 42
Hi,
any ideas how I should do db-connection to my application? It is supposed to be portable meaning that it doesnt matter matter if os is linux or windows etc. Where to start, how to code, just basic information or links, anything?
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1506
I would start with the JDBC tutorial at Sun's site.


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
tormod eriksen
Ranch Hand

Joined: Jan 23, 2002
Posts: 52
first you must register a driver. this can be done this way:
DriverManager.registerDriver((Driver)Class.forName( <driverpath> ).newInstance())
where <driverpath> is a string with the path to the driverclass on your system.
Then you can use one of the DriverManager.getConnection methods to get a connection.
possible structure:
Connection conn
conn = DriverManager.getConnection( <url> , <username>, <password > )
the three arguments to getConnection are strings.
link to the DriverManager class in the java 1.3 api : http://java.sun.com/j2se/1.3/docs/api/java/sql/DriverManager.html
if you can't figure out the format for the url to use, check out the documentation for the database you are trying to connect to.
hope it helps!
[ Edited by Dave to remove smilies ]
[ May 30, 2002: Message edited by: David O'Meara ]
Martin Schneider
Ranch Hand

Joined: May 16, 2002
Posts: 42
Ok,
so lets say I want to install my application to computer that has windows as operating system and access as db. I put these lines into my source:

?
And if I want to use some other db then I put something else? What Im asking is can I control only by those two lines connecting to database and I dont have to do any other changes?
[ Edited by Dave to remove smilies ]
[ May 30, 2002: Message edited by: David O'Meara ]
tormod eriksen
Ranch Hand

Joined: Jan 23, 2002
Posts: 52
to a certain extent you can control connecting to a datebase with these two statements (register the driver, and opening a connection)
but drivers for different databases implements a different set of the methods defined in the jdbc api.
so if you change from one database/driver, to another, then there may be some methods that you use, that isn't implemented by the new database/driver.
if you stick to 'basic' api calls you should be pretty safe with most databases/drivers.
Martin Schneider
Ranch Hand

Joined: May 16, 2002
Posts: 42
Okay, thanks.
I think I stick with the basic I guess those method available from db's are listed somewhere...
tormod eriksen
Ranch Hand

Joined: Jan 23, 2002
Posts: 52
if not actually providing a simple list over supported methods, there's probably some documentation available, possibly downloadable from the db vendors website, which includes topics such as hints to what jdbc version, methods it supports, examples on use and installation instructions.
here is a link to the sdk 1.3 api listing. with this comes the api for jdbc 2, which you will find under java.sql.
http://java.sun.com/j2se/1.3/docs/api/index.html
here's a link to a place where you can search for information on jdbc drivers.
http://industry.java.sun.com/products/jdbc/drivers
i would think that all major relational databases support basic jdbc plus more or less advanced.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: DB-newbie
 
Similar Threads
I get You are not authorised to view this Page when I click on a button
OOD and database schema
Modifying Auto Increment column using servlets
Allen/Bambara SCEA guide - strange Q's
About the GUI and locks