Free Jobs
Reference




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: Describe the complete process of accessing a Datasource using JDBC and Java

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

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





User: shruti888 Post Date: 05 Jun 2011 11:07

Introduction:
JDBC is a standard API to access databases by Java programsIn this post I will
describe the step by step process of accesing a Datasource using JDBC and Java



Main Content:

Below are the steps:


1.The first step is to load a JDBC driver


2.Create the instance of JDBC driver and register it with the driver manager.


Note that both the above steps can be carried out by following line of code:


Class.forName("package.DriverName");


3.Create a connection to the database :


this can be done by calling getConnection() method of DriverManager as given below


Connection MyConn = DriverManager.getConnection(dbURL,myUSERNAME,myPASSWORD);


4.Create a SQL Statement:


once the connction object is created we can create the SQL statement

by using createStatement() method of connction object as below:


Statement myStatement = MyConn.createStatement();


5.use the different methods of statement Interface to get the resultsets


there are thre main methods of Statement Interface


execute,executeQuery,executeUpdate and executeBatch


use any one of them to get the resultset as below:


ResultSet myResult = myStatement.executeQuery("Select * from My Table");




Now use while loop like below to process the resultset


while(myResult.next())

{

//process data

}


Conclusion:
Thus we can get data using JDBC from DATABASE



About Writer:
Hi I am Java Developer from Bangalore


Writer's Link:

Writer's Email:







Comments:
Post Comment





Similar Articles Top ArticlesLatest Articles Other Articles by this Author







www.freejobsreference.com 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)