<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>JDBC Tutorials Examples Downloads Programs</title>
	<atom:link href="http://jdbctutorials.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://jdbctutorials.wordpress.com</link>
	<description>Just another WordPress.com weblog</description>
	<lastBuildDate>Thu, 05 Feb 2009 08:22:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='jdbctutorials.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>JDBC Tutorials Examples Downloads Programs</title>
		<link>http://jdbctutorials.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://jdbctutorials.wordpress.com/osd.xml" title="JDBC Tutorials Examples Downloads Programs" />
	<atom:link rel='hub' href='http://jdbctutorials.wordpress.com/?pushpress=hub'/>
		<item>
		<title>JDBC Basics &#8211; Java Database Connectivity Steps</title>
		<link>http://jdbctutorials.wordpress.com/2009/02/05/jdbc-basics-java-database-connectivity-steps/</link>
		<comments>http://jdbctutorials.wordpress.com/2009/02/05/jdbc-basics-java-database-connectivity-steps/#comments</comments>
		<pubDate>Thu, 05 Feb 2009 08:12:18 +0000</pubDate>
		<dc:creator>javadevoted</dc:creator>
				<category><![CDATA[Programs]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[connectivity]]></category>
		<category><![CDATA[jdbc basics]]></category>

		<guid isPermaLink="false">http://jdbctutorials.wordpress.com/?p=36</guid>
		<description><![CDATA[Before you can create a java jdbc connection to the database, you must first import the java.sql package. import java.sql.*; The star ( * ) indicates that all of the classes in the package java.sql are to be imported. 1. Loading a database driver, In this step of the jdbc connection process, we load the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jdbctutorials.wordpress.com&amp;blog=6459246&amp;post=36&amp;subd=jdbctutorials&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Before you can create a java jdbc connection to the database, you must first import the<br />
java.sql package.</p>
<p>import java.sql.*;    The star ( * ) indicates that all of the classes in the package java.sql are to be imported.</p>
<p class="style7"><strong>1. Loading a database driver,</strong></p>
<p>In this step of the jdbc connection process, we load the driver class by calling Class.forName() with the Driver class name as an argument. Once loaded, the Driver class creates an instance of itself. A client can connect to Database Server through JDBC Driver. Since most of the Database servers support ODBC driver therefore JDBC-ODBC Bridge driver is commonly used.<br />
The return type of the Class.forName                         (String ClassName) method is “Class”. Class is a class in<br />
java.lang package.</p>
<pre><span style="font-size:small;">try {
	Class.forName(”sun.jdbc.odbc.JdbcOdbcDriver”);
       //Or any other driver
}
catch(Exception x){
	System.out.println( “Unable to load
       the driver class!” );
}</span>
<strong><span style="font-size:small;">
</span><span style="font-size:15px;">2. Creating a oracle jdbc Connection</span></strong><strong>
</strong>
<span style="font-size:small;"><span style="text-decoration:underline;">JDBC URL Syntax</span>::    jdbc: &lt;subprotocol&gt;: &lt;subname&gt;
</span></pre>
<p><span style="text-decoration:underline;">JDBC URL Example</span>:: jdbc: &lt;subprotocol&gt;: &lt;subname&gt;•Each driver has its own subprotocol<br />
•Each subprotocol has its own syntax for the source. We’re using the jdbc odbc subprotocol, so the DriverManager knows to use the sun.jdbc.odbc.JdbcOdbcDriver.</p>
<pre><span style="font-size:small;">try{
 Connection dbConnection=DriverManager.
 getConnection(url,”loginName”,”Password”)
}
catch( SQLException x ){
	System.out.println( “Couldn’t get connection!” );
}

</span></pre>
<p><strong class="style7">3. Creating a jdbc Statement object, </strong></p>
<p>Once a connection is obtained we can interact with the database. Connection interface defines methods for interacting with the database via the established connection. To execute SQL statements, you need to instantiate a Statement object from your connection object by using the createStatement() method.</p>
<p>Statement statement = dbConnection.createStatement();</p>
<p>A statement object is used to send and execute SQL statements to a database.</p>
<p class="style6"><span style="font-weight:400;"> <span style="font-size:small;">Three kinds of Statements</span></span></p>
<p><strong>Statement:</strong> Execute simple sql queries without parameters.<br />
Statement createStatement()<br />
Creates an SQL Statement object.</p>
<p><strong>Prepared Statement:</strong> Execute precompiled sql queries with or without parameters.<br />
PreparedStatement prepareStatement(String sql)<br />
returns a new PreparedStatement object. PreparedStatement objects are precompiled<br />
SQL statements.</p>
<p><strong>Callable Statement:</strong> Execute a call to a database stored procedure.<br />
CallableStatement prepareCall(String sql)<br />
returns a new CallableStatement object.  CallableStatement objects are SQL stored procedure call statements.</p>
<p class="style7"><strong>4. Executing a SQL statement with the Statement object, and returning a  					jdbc resultSet. </strong></p>
<p>Statement interface defines methods that are used to interact with database via the execution of SQL statements. The Statement class has three methods for executing statements:<br />
executeQuery(), executeUpdate(), and execute(). For a SELECT statement, the method to use is executeQuery . For statements that create or modify tables, the method to use is executeUpdate. Note: Statements that create a table, alter a table, or drop a table are all examples of DDL<br />
statements and are executed with the method                         executeUpdate. execute() executes an SQL<br />
statement that is written as String object.</p>
<p><strong>ResultSet</strong> provides access to a table of data generated by executing a Statement. The table rows are retrieved in sequence. A ResultSet maintains a cursor pointing to its current row of data. The next() method is used to successively step through the rows of the tabular results.</p>
<p><strong>ResultSetMetaData</strong> Interface holds information on the types and properties of the columns in a ResultSet. It is constructed from the Connection object.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jdbctutorials.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jdbctutorials.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jdbctutorials.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jdbctutorials.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jdbctutorials.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jdbctutorials.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jdbctutorials.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jdbctutorials.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jdbctutorials.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jdbctutorials.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jdbctutorials.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jdbctutorials.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jdbctutorials.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jdbctutorials.wordpress.com/36/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jdbctutorials.wordpress.com&amp;blog=6459246&amp;post=36&amp;subd=jdbctutorials&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jdbctutorials.wordpress.com/2009/02/05/jdbc-basics-java-database-connectivity-steps/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4767cb40cbc765ffbe1675d22085388d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">javadevoted</media:title>
		</media:content>
	</item>
		<item>
		<title>JDBC Connection Example, JDBC Driver Example</title>
		<link>http://jdbctutorials.wordpress.com/2009/02/05/jdbc-connection-example-jdbc-driver-example/</link>
		<comments>http://jdbctutorials.wordpress.com/2009/02/05/jdbc-connection-example-jdbc-driver-example/#comments</comments>
		<pubDate>Thu, 05 Feb 2009 08:00:25 +0000</pubDate>
		<dc:creator>javadevoted</dc:creator>
				<category><![CDATA[Programs]]></category>
		<category><![CDATA[jdbc connection example]]></category>

		<guid isPermaLink="false">http://jdbctutorials.wordpress.com/?p=32</guid>
		<description><![CDATA[import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.DriverManager; import java.sql.SQLException; public class JDBCDriverInformation { static String userid=”scott”, password = “tiger”; static String url = “jdbc:odbc:bob”; static Connection con = null; public static void main(String[] args) throws Exception { Connection con = getOracleJDBCConnection(); if(con!= null){ System.out.println(”Got Connection.”); DatabaseMetaData meta = con.getMetaData(); System.out.println(”Driver Name : “+ meta.getDriverName()); System.out.println(”Driver Version [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jdbctutorials.wordpress.com&amp;blog=6459246&amp;post=32&amp;subd=jdbctutorials&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<pre><span style="font-size:small;">import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.SQLException;

public class JDBCDriverInformation {
	static String userid=”scott”, password = “tiger”;
	static String url = “jdbc:odbc:bob”;	</span></pre>
<pre><span style="font-size:small;">	static Connection con = null;
	public static void main(String[] args) throws Exception {
	    Connection con = getOracleJDBCConnection();
	    if(con!= null){
	       System.out.println(”Got Connection.”);
	       DatabaseMetaData meta = con.getMetaData();
	       System.out.println(”Driver Name : “+
               meta.getDriverName());
	       System.out.println(”Driver Version :
               “+meta.getDriverVersion());

	    }else{
		    System.out.println(”Could not Get Connection”);
	    }
	}

	public static Connection getOracleJDBCConnection(){

		try {
			Class.forName(”sun.jdbc.odbc.JdbcOdbcDriver”);	</span></pre>
<pre><span style="font-size:small;">		} catch(java.lang.ClassNotFoundException e) {
			System.err.print(”ClassNotFoundException: “);
			System.err.println(e.getMessage());
		}

		try {
		   con = DriverManager.getConnection(url, userid,
                   password);
		} catch(SQLException ex) {
			System.err.println(”SQLException: ” +
                        ex.getMessage());
		}

		return con;
	}

}
</span></pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jdbctutorials.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jdbctutorials.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jdbctutorials.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jdbctutorials.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jdbctutorials.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jdbctutorials.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jdbctutorials.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jdbctutorials.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jdbctutorials.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jdbctutorials.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jdbctutorials.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jdbctutorials.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jdbctutorials.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jdbctutorials.wordpress.com/32/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jdbctutorials.wordpress.com&amp;blog=6459246&amp;post=32&amp;subd=jdbctutorials&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jdbctutorials.wordpress.com/2009/02/05/jdbc-connection-example-jdbc-driver-example/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4767cb40cbc765ffbe1675d22085388d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">javadevoted</media:title>
		</media:content>
	</item>
		<item>
		<title>JDBC Interview Questions</title>
		<link>http://jdbctutorials.wordpress.com/2009/02/05/jdbc-interview-questions/</link>
		<comments>http://jdbctutorials.wordpress.com/2009/02/05/jdbc-interview-questions/#comments</comments>
		<pubDate>Thu, 05 Feb 2009 07:52:30 +0000</pubDate>
		<dc:creator>javadevoted</dc:creator>
				<category><![CDATA[Interview]]></category>
		<category><![CDATA[jdbc interview questions]]></category>

		<guid isPermaLink="false">http://jdbctutorials.wordpress.com/?p=27</guid>
		<description><![CDATA[Q. What are 4 drivers available in JDBC and What situation , each of the 4 drivers used ? Ans. Type 1: JDBC-ODBC Bridge The type 1 driver, JDBC-ODBC Bridge, translates all JDBC calls into ODBC (Open DataBase Connectivity) calls and sends them to the ODBC driver. As such, the ODBC driver, as well as, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jdbctutorials.wordpress.com&amp;blog=6459246&amp;post=27&amp;subd=jdbctutorials&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div class="entrytext">
<div class="snap_preview">
<p><strong>Q. What are 4 drivers available in JDBC and What situation , each of the 4 drivers used ?</strong><br />
Ans.<br />
<strong><span style="color:#cc0000;">Type 1: JDBC-ODBC Bridge</span></strong> The type 1 driver, JDBC-ODBC Bridge, translates all JDBC calls into ODBC (Open DataBase Connectivity) calls and sends them to the ODBC driver. As such, the ODBC driver, as well as, in many cases, the client database code, must be present on the client machine. May be used when an ODBC driver has already been installed on client machine and performance is not an issue.<br />
<strong><br /><span style="color:#cc0000;">Type 2: Native-API/partly Java driver</span></strong> JDBC driver type 2 — the native-API/partly Java driver — converts JDBC calls into database-specific calls for databases such as SQL Server, Informix, Oracle, or Sybase. The type 2 driver communicates directly with the database server; therefore it requires that some binary code be present on the client machine. Can be used when application is not for internet.<br />
<strong><br /><span style="color:#cc0000;">Type 3: Net-protocol/all-Java driver</span></strong> JDBC driver type 3 — the net-protocol/all-Java driver — follows a three-tiered approach whereby the JDBC database requests are passed through the network to the middle-tier server. The middle-tier server then translates the request (directly or indirectly) to the database-specific native-connectivity interface to further the request to the database server. If the middle-tier server is written in Java, it can use a type 1 or type 2 JDBC driver to do this.Type 3 drivers are best suited for environments that need to provide connectivity to a variety of DBMS servers and heterogeneous databases and that require significantly high levels of concurrently connected users where performance and scalability are major concerns.<br />
<span style="color:#cc0000;"><br /><strong>Type 4: Native-protocol/all-Java driver</strong></span> The native-protocol/all-Java driver (JDBC driver type 4) converts JDBC calls into the vendor-specific database management system (DBMS) protocol so that client applications can communicate directly with the database server. Level 4 drivers are completely implemented in Java to achieve platform independence and eliminate deployment administration issues. Useful for Internet-related applications.</p>
<p><strong>Q. Prepared statement?</strong><br />
Ans. Prepared statements are pre-compiled statements. It is mainly used to speed up the process of inserting/ deleting/ updating , especially when there is a bulk processing.</p>
<p><strong>Q. Callable statement?</strong><br />
Ans. Used to invoke the stored procedures.<br />
con.prepareCall(String sql)<br />
con.prepareCall(String sql, int resultSetType, int resultSetConcurrency)</p>
<p><span style="color:#990000;"><strong>JDBC-ODBC bridge is NOT multi-threaded</strong></span><br />
<span style="color:#990000;"><strong>It does NOT support multiple open statements per connection.</strong></span></div>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jdbctutorials.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jdbctutorials.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jdbctutorials.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jdbctutorials.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jdbctutorials.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jdbctutorials.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jdbctutorials.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jdbctutorials.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jdbctutorials.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jdbctutorials.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jdbctutorials.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jdbctutorials.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jdbctutorials.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jdbctutorials.wordpress.com/27/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jdbctutorials.wordpress.com&amp;blog=6459246&amp;post=27&amp;subd=jdbctutorials&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jdbctutorials.wordpress.com/2009/02/05/jdbc-interview-questions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4767cb40cbc765ffbe1675d22085388d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">javadevoted</media:title>
		</media:content>
	</item>
		<item>
		<title>JDBC Connectivity Sample Code</title>
		<link>http://jdbctutorials.wordpress.com/2009/02/05/jdbc-connectivity-sample-code/</link>
		<comments>http://jdbctutorials.wordpress.com/2009/02/05/jdbc-connectivity-sample-code/#comments</comments>
		<pubDate>Thu, 05 Feb 2009 07:22:31 +0000</pubDate>
		<dc:creator>javadevoted</dc:creator>
				<category><![CDATA[Programs]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[execute query]]></category>
		<category><![CDATA[jdbc connectivity sample code]]></category>

		<guid isPermaLink="false">http://jdbctutorials.wordpress.com/?p=13</guid>
		<description><![CDATA[Connecting to a database In order to connect to a database, you need to perform some initialization first. Your JDBC driver has to be loaded by the Java Virtual Machine classloader, and your application needs to check to see that the driver was successfully loaded. We&#8217;ll be using the ODBC bridge driver, but if your [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jdbctutorials.wordpress.com&amp;blog=6459246&amp;post=13&amp;subd=jdbctutorials&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h2>Connecting to a database</h2>
<p>In order to connect to a database, you need to perform some initialization first. Your JDBC driver has to be loaded by the Java Virtual Machine classloader, and your application needs to check to see that the driver was successfully loaded. We&#8217;ll be using the ODBC bridge driver, but if your database vendor supplies a JDBC driver, feel free to use it instead.</p>
<pre style="font-size:11px;"><span style="color:#800080;font-size:13px;">// Attempt to load database driver</span>
<span style="color:#0000ff;font-size:13px;">try</span>
{
	<span style="color:#800080;font-size:13px;">// Load Sun's jdbc-odbc driver</span>
	Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
}
<span style="color:#0000ff;font-size:13px;">catch</span> (ClassNotFoundException cnfe) <span style="color:#800080;font-size:13px;">// driver not found</span>
{
	System.err.println ("Unable to load database driver");
	System.err.println ("Details : " + cnfe);
	System.exit(0);
}</pre>
<p>We try to load the JdbcOdbcDriver class, and then catch the ClassNotFoundException if it is thrown. This is important, because the application might be run on a non-Sun virtual machine that doesn&#8217;t include the ODBC bridge, such as Microsoft&#8217;s JVM. If this occurs, the driver won&#8217;t be installed, and our application should exit gracefully.</p>
<p>Once our driver is loaded, we can connect to the database. We&#8217;ll connect via the driver manager class, which selects the appropriate driver for the database we specify. In this case, we&#8217;ll only be using an ODBC database, but in more complex applications, we might wish to use different drivers to connect to multiple databases. We identify our database through a URL. No, we&#8217;re not doing anything on the web in this example &#8211; a URL just helps to identify our database.</p>
<p>A JDBC URL starts with &#8220;jdbc:&#8221;  This indicates the protocol (JDBC). We also specify our database in the URL. As an example, here&#8217;s the URL for an ODBC datasource called &#8216;demo&#8217;. Our final URL looks like this :</p>
<blockquote><p>jdbc:odbc:demo</p></blockquote>
<p>To connect to the database, we create a string representation of the database. We take the name of the datasource from the command line, and attempt to connect as user &#8220;dba&#8221;, whose password is &#8220;sql&#8221;.</p>
<pre style="font-size:11px;"><span style="color:#800080;font-size:13px;">// Create a URL that identifies database
</span>String url = "jdbc:odbc:" + args[0];

<span style="color:#800080;font-size:13px;">// Now attempt to create a database connection</span>
Connection db_connection =
	DriverManager.getConnection (url, "dba", "sql");</pre>
<p>As you can see, connecting to a database doesn&#8217;t take much code.</p>
<h2>Executing database queries</h2>
<p>In JDBC, we use a statement object to execute queries. A statement object is responsible for sending the SQL statement, and returning a set of results, if needed, from the query. Statement objects support two main types of statements &#8211; an update statement that is normally used for operations which don&#8217;t generate a response, and a query statement that returns data.</p>
<pre style="font-size:11px;"><span style="color:#800000;font-size:13px;">// Create a statement to send SQL
</span>Statement db_statement = db_connection.createStatement();</pre>
<p>Once you have an instance of a statement object, you can call its executeUpdate and executeQuery methods. To illustrate the executeUpdate command, we&#8217;ll create a table that stores information about employees. We&#8217;ll keep things simple and limit it to name and employee ID.</p>
<pre style="font-size:11px;"><span style="color:#800000;font-size:13px;">// Create a simple table, which stores an employee ID and name</span>
db_statement.executeUpdate
   ("create table employee { int id, char(50) name };");</pre>
<pre style="font-size:11px;"><span style="color:#800000;font-size:13px;">// Insert an employee, so the table contains data</span>
db_statement.executeUpdate
   ("insert into employee values (1, 'John Doe');");</pre>
<pre style="font-size:11px;"><span style="color:#800000;font-size:13px;">// Commit changes</span>
db_connection.commit();</pre>
<p>Now that there&#8217;s data in the table, we can execute queries. The response to a query will be returned by the executeQuery method as a ResultSet object. ResultSet objects store the last response to a query for a given statement object. Instances of ResultSet have methods following the pattern of getXX where XX is the name of a data type. Such data types include numbers (bytes, ints, shorts, longs, doubles, big-decimals), as well as strings, booleans, timestamps and binary data.</p>
<pre style="font-size:11px;"><span style="color:#800000;font-size:13px;">// Execute query</span>
ResultSet result = db_statement.executeQuery
	("select * from employee");

<span style="color:#800000;font-size:13px;">// While more rows exist, print them</span>
<span style="color:#0000ff;font-size:13px;">while</span> (result.next() )
{
	<span style="color:#800000;font-size:13px;">// Use the getInt method to obtain emp. id</span>
	System.out.println ("ID : " + result.getInt("ID"));

	<span style="color:#800000;font-size:13px;">// Use the getString method to obtain emp. name</span>
	System.out.println ("Name : " + result.getString("Name"));
	System.out.println ();
}</pre>
<h2>Putting it all together</h2>
<p>To show you just how JDBC applications work, I&#8217;ve put together a simple demonstration, that allows users to insert new employees into the system, and to obtain a list. The demonstration uses ODBC to connect to an Access database, which can be downloaded along with the source code.</p>
<p>Running the sample application is quite straightforward. First, you&#8217;ll need to create an ODBC datasource for the access database. Next, using JDK1.1 or higher, run the JDBCDemo application, and pass the datasource name as a parameter.</p>
<pre style="font-size:11px;">	java JDBCDEMO demo</pre>
<p>The demonstration application presents you with a menu, containing three options. Choosing the first operation allows you to add a new employee, using the SQL insert statement. Choosing the second option displays all employees in the system, using the SQL select statement. Finally, the third option closes the database connection and exits.</p>
<h2>
<pre style="font-size:13px;">Menu

1. Add new employee
2. Show all employees
3. Exit
Choice : 1
ID : 3
Name : Bill Gates</pre>
<pre style="font-size:11px;">Menu

1. Add new employee
2. Show all employees
3. Exit
Choice : 2
ID : 1
Name : David Reilly

ID : 2
Name : John Doe

ID : 3
Name : Bill Gates</pre>
</h2>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jdbctutorials.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jdbctutorials.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jdbctutorials.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jdbctutorials.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jdbctutorials.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jdbctutorials.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jdbctutorials.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jdbctutorials.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jdbctutorials.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jdbctutorials.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jdbctutorials.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jdbctutorials.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jdbctutorials.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jdbctutorials.wordpress.com/13/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jdbctutorials.wordpress.com&amp;blog=6459246&amp;post=13&amp;subd=jdbctutorials&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jdbctutorials.wordpress.com/2009/02/05/jdbc-connectivity-sample-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4767cb40cbc765ffbe1675d22085388d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">javadevoted</media:title>
		</media:content>
	</item>
		<item>
		<title>JDBC Introduction</title>
		<link>http://jdbctutorials.wordpress.com/2009/02/05/jdbc-introduction/</link>
		<comments>http://jdbctutorials.wordpress.com/2009/02/05/jdbc-introduction/#comments</comments>
		<pubDate>Thu, 05 Feb 2009 05:40:22 +0000</pubDate>
		<dc:creator>javadevoted</dc:creator>
				<category><![CDATA[Introduction]]></category>
		<category><![CDATA[jdbc driver types]]></category>
		<category><![CDATA[jdbc introduction]]></category>
		<category><![CDATA[jdbc use]]></category>

		<guid isPermaLink="false">http://jdbctutorials.wordpress.com/?p=3</guid>
		<description><![CDATA[Introduction This article introduce you with JDBC and shows you how to our search engine with database. What is JDBC? Java Database Connectivity or JDBC for short is set of Java API&#8217;s that enables the developers to create platform and database independent applications in java. The biggest advantage of programming in Java is its platform [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jdbctutorials.wordpress.com&amp;blog=6459246&amp;post=3&amp;subd=jdbctutorials&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<table style="height:127px;" border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td colspan="3" width="100%"><span style="font-family:Arial,Helvetica;color:#000080;font-size:medium;">Introduction</span></span></p>
<p><span style="color:#000080;"><span style="font-family:Arial,Helvetica;font-size:large;">T</span><span style="font-family:Arial,Helvetica;font-size:x-medium;">his           article introduce you with JDBC and shows you how to our search engine           with <span style="position:static;text-decoration:underline;"><span style="color:blue!important;font-weight:400;font-size:13px;position:static;"><span class="kLink" style="color:blue!important;font-family:Arial,Helvetica;font-weight:400;font-size:13px;position:static;">database</span></span></span>. </span></span></p>
<p><span style="font-family:Arial,Helvetica;color:#000080;font-size:medium;">What is JDBC?</span></p>
<p><span style="color:#000080;"><span style="font-family:Arial,Helvetica;font-size:large;">J</span><span style="font-family:Arial,Helvetica;font-size:13px;">ava           Database Connectivity or JDBC for short is set of Java API&#8217;s that           enables the <span style="position:static;text-decoration:underline;"><span style="color:blue!important;font-weight:400;font-size:13px;position:static;"><span class="kLink" style="color:blue!important;font-family:Arial,Helvetica;font-weight:400;font-size:13px;position:static;">developers</span></span></span> to create platform and database independent           <span style="position:static;text-decoration:underline;"><span style="color:blue!important;font-weight:400;font-size:13px;position:static;"><span class="kLink" style="border-bottom:1px solid blue;color:blue!important;font-family:Arial,Helvetica;font-weight:400;font-size:13px;position:static;background-color:transparent;">applications</span></span></span></span></span></p>
<div id="preLoadLayer2" style="position:absolute;z-index:4000;top:-32px;left:-18px;display:none;"><img style="border:0 none;" src="http://kona.kontera.com/javascript/lib/imgs/grey_loader.gif" alt="" /></div>
<p>in java. The biggest advantage of programming in Java is           its platform independence. An application written to access the MS           Access database on Win 95/Win NT platform can work on <span style="position:static;text-decoration:underline;"><span style="color:blue!important;font-weight:400;font-size:13px;position:static;"><span class="kLink" style="color:blue!important;font-family:Arial,Helvetica;font-weight:400;font-size:13px;position:static;">Linux</span></span></span> against           Oracle database, only by changing the name of driver, provided none of           the database calls it makes are vendor specific.</p>
<p><span style="font-family:Arial,Helvetica;color:#000080;font-size:medium;">What are           JDBC Drivers?</span></p>
<p><span style="color:#000080;"><span style="font-family:Arial,Helvetica;font-size:large;">J</span><span style="font-family:Arial,Helvetica;font-size:13px;">DBC           Drivers are set of classes that enables the Java application to           communicate with databases. Java.sql that ships with JDK contains           various classes for using relational databases. But these classes do           not provide any implementation, only the behaviors are defined. The           actual implementations are done in third-party drivers. Third party           vendors implements the java.sql.Driver interface in their database           driver. A list of currently available JDBC drivers can be found at <a href="http://java.sun.com/products/jdbc/jdbc.drivers.html" target="_blank">http://java.sun.com/products/jdbc/jdbc.drivers.html</a></span></span></p>
<p><span style="font-family:Arial,Helvetica;color:#000080;font-size:medium;">JDBC Drivers           Types</span></p>
<p><span style="color:#000080;"><span style="font-family:Arial,Helvetica;font-size:large;">S</span><span style="font-family:Arial,Helvetica;font-size:13px;">un           has defined four JDBC driver types. These are:</span> </span></p>
<ol>
<li><span style="font-family:Arial,Helvetica;color:#000080;font-size:13px;"><strong>Type 1: JDBC-ODBC               Bridge Driver</strong><br />
The first type of JDBC driver is JDBC-ODBC Bridge which provide               JDBC access to any ODBC complaint databases through ODBC drivers.               Sun&#8217;s JDBC-ODBC bridge is example of type 1 driver.</span></li>
<li><span style="font-family:Arial,Helvetica;color:#000080;font-size:13px;"><strong>Type 2: Native               -API Partly &#8211; Java Driver</strong><br />
Type 2 drivers are developed using native code libraries, which               were originally designed for accessing the database through C/C++.               Here a thin code of Java wrap around the native code and converts               JDBC commands to DBMS-specific native calls.</span></li>
<li><span style="font-family:Arial,Helvetica;color:#000080;font-size:13px;"><strong>Type 3: JDBC-Net               Pure Java Driver</strong><br />
Type 3 drivers are a three-tier solutions. This type of driver               communicates to a middleware component which in turn connects to               database and provide database connectivity.</span></li>
<li><span style="font-family:Arial,Helvetica;color:#000080;font-size:13px;"><strong>Type 4:               Native-Protocol Pure Java Driver</strong><br />
Type 4 drivers are entirely written in Java that communicate               directly with vendor&#8217;s database through socket connection. Here no               <span style="position:static;text-decoration:underline;"><span style="color:blue!important;font-weight:400;font-size:13px;position:static;"><span class="kLink" style="color:blue!important;font-family:Arial,Helvetica;font-weight:400;font-size:13px;position:static;">translation</span></span></span> or middleware layer, are required which improves               performance tremendously.</span></li>
</ol>
</td>
</tr>
<tr>
<td colspan="3" width="100%"><span style="font-family:Arial,Helvetica;color:#000080;font-size:medium;">Links           to JDBC Drivers Site</span></td>
</tr>
<tr>
<td colspan="3" width="100%"><span style="color:#000080;"> </span></p>
<ol>
<li><span style="font-family:Arial,Helvetica;color:#000080;font-size:13px;"><a href="http://www.ddjava.com/" target="_blank">MERANT               DataDirect </a>provides JDBC driver technology through n-tier,               server-based data connectivity and high-performance,               DBMS-independent JDBC middleware.<br />
</span></li>
<li><span style="font-family:Arial,Helvetica;color:#000080;font-size:13px;"><a href="http://www.worldserver.com/mm.mysql" target="_blank">MM               MySQL JDBC DRIVERS</a> &#8211; 100% pure java driver for MySQL and is               distributed  under the <a href="http://www.gnu.org/copyleft/gpl.html">GNU               LGPL</a>.<br />
</span></li>
<li><span style="font-family:Arial,Helvetica;color:#000080;font-size:13px;"><a href="http://www.imaginary.com/">The               mSQL JDBC Driver</a>-A pure-java JDBC driver for mSQL was created               and is being maintained by George Reese from The Center for               Imaginary Environments.</span></li>
</ol>
</td>
</tr>
</tbody>
</table>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jdbctutorials.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jdbctutorials.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jdbctutorials.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jdbctutorials.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jdbctutorials.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jdbctutorials.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jdbctutorials.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jdbctutorials.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jdbctutorials.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jdbctutorials.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jdbctutorials.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jdbctutorials.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jdbctutorials.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jdbctutorials.wordpress.com/3/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jdbctutorials.wordpress.com&amp;blog=6459246&amp;post=3&amp;subd=jdbctutorials&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jdbctutorials.wordpress.com/2009/02/05/jdbc-introduction/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4767cb40cbc765ffbe1675d22085388d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">javadevoted</media:title>
		</media:content>

		<media:content url="http://kona.kontera.com/javascript/lib/imgs/grey_loader.gif" medium="image" />
	</item>
	</channel>
</rss>
