Free Jobs

Java Forums: Core Java (15) J2EE (3) EJB (5) Servlet (3) JDBC (6) Hibernate (2) Struts (1) Swing (1) Oracle (7) JSP (4) Other (10)

Topic: How to access database in Java using JDBC technology

To get the Posted Questions details daily in your mail Click Here

Share this Post on Facebook/Twitter/Orkut Bookmark and Share

User: mohit555 Post Date: 29 Oct 2010 06:19

JDBC stands for Java Database Connectivity.It is a J2EE API that provides
cross-Database connectivity to a wide range of SQL databases.

Main Content:
With a JDBC technology enabled driver we can connect to all corporate data
even if it is in a heterogeneous environment. JDBC provides Java
developers with a standard API that is used to access databases,
irrespective of the driver and database product.
To use JDBC, we need JDK 1.1, a database, and a JDBC driver and if we are
changing the databases we just need to change their driver.

code to load the driver

The JDBC driver has to be loaded by the Java Virtual Machine classloader,
and the application needs to check to see that the driver was
successfully loaded.For the illustration purpose we have used ODBC bridge
driver here.

// Load jdbc-odbc driver

Code to connect to database
After the driver is loaded, we can connect to the database.
In JDBC database is represented by a URL. Remeber that it is not llike a
web URL.The JDBC database URL is as shown below.jdbc:odbc:TestUrl

String urlData = "jdbc:odbc:TestUrl";
Connection mydb_conn = DriverManager.getConnection (urlData, "abc", "xyz");

Note that in the above code abc is usename and xyz is password for database.

Code for writing database queries:
Then after connecting to database we can write the below code for
different resultset.
Statement mydb_stat = mydb_conn.createStatement();
ResultSet myresult = mydb_stat.executeQuery("select * from employee");

So in this article we read how to load a database driver , connect to the
database and execute query in database using java and JDBC.

About Writer:
Hi All,I am Java Developer From Bangalore

Writer's Link:

Writer's Email:

Post Comment

Similar Articles Top ArticlesLatest Articles Other Articles by this Author Copyright © 2009-2011 | All Rights Reserved
All content of this website is protected by copyright laws and should not be reproduced in any form or by any means without written permission
(Best viewed in IE 8.0+ or Firefox 3.0+ at resolution of 1024 * 768 or higher)