First of all we have to know what is JDBC
What is JDBC?
JDBC is a piece of software that knows how to talk to the actual database server. JDBC is a registered trade mark.

Steps for JDBC
There are seven standard steps in querying databases:
- Load the JDBC driver.
- Define the connection URL.
- Establish the connection.
- Create a statement object.
- Execute a query or update.
- Process the results.
- Close the connection.
Sample program
import java.sql.* ;
class JDBCQuery
{
public static void main( String args[] )
{
try
{
// Load the database driver
Class.forName( “sun.jdbc.odbc.JdbcOdbcDriver” ) ;
// Get a connection to the database
Connection conn = DriverManager.getConnection( “jdbc:odbc:Database” ) ;
// DriverManager.getConnection(“jdbc:mysql://localhost/test?user=root&password=mypass”);
// Print all warnings
for( SQLWarning warn = conn.getWarnings(); warn != null; warn = warn.getNextWarning() )
{
System.out.println( “SQL Warning:” ) ;
System.out.println( “State : ” + warn.getSQLState() ) ;
System.out.println( “Message: ” + warn.getMessage() ) ;
System.out.println( “Error : ” + warn.getErrorCode() ) ;
}
// Get a statement from the connection
Statement stmt = conn.createStatement() ;
// Execute the query
ResultSet rs = stmt.executeQuery( “SELECT * FROM Cust” ) ;
// Loop through the result set
while( rs.next() )
System.out.println( rs.getString(1) ) ;
// Close the result set, statement and the connection
rs.close() ;
stmt.close() ;
conn.close() ;
}
catch( SQLException se )
{
System.out.println( “SQL Exception:” ) ;
// Loop through the SQL Exceptions
while( se != null )
{
System.out.println( “State : ” + se.getSQLState() ) ;
System.out.println( “Message: ” + se.getMessage() ) ;
System.out.println( “Error : ” + se.getErrorCode() ) ;
se = se.getNextException() ;
}
}
catch( Exception e )
{
System.out.println( e ) ;
}
}
}
Executing CREATE/INSERT/UPDATE Statements
To execute the create/insert/update statements we can use
stmt.executeUpdate(”);
Yes synthia. You are correct. In next post i will post the information about the types of statements.
Hey,
This really gives basic idea about JDBC..
Keep sharing.
Hi,
Good one.
if you are looking for any ebooks go for
http://javaopensource.net