The code illustrates an example from JDBC-ODBC Connectivity. The code helps you in retrieve the name and size of the column. To understand this example we have a class JdbcOdbcConnectivity ,the class include a main method ( ) follows a list of step in it -
Importing a package java.sql,provides you a network interface for the interaction between front-end application in java and database in the backend.
The first step inside the main method ( ) is to load a driver by calling class.forName ( ) by accepting driver class as argument.
DriverManager.getConnection ( ) :The Driver Manager call getConnection ( ) returns you an object of connection class. This method is used to built a connection between url and database. The Connection object call createStatement ( ),this return you a sql object to send and execute SQL Statements in database.
executeQuery ( ) : This method return you a record set from a table using select query in sql.The obtained record set is stored in result set.
get Metadata ( ) : This method return you the property of the column's data type, size, the methods, properties, and parameters of a component associated with object in an application.
get ColumnCount ( ): This method return you the number of column in a result set.
Finally the println print the column name
get Column Display Size ( ): This method return you the designated column's normal maximum width in characters.
In case there exists an exception in try block, the catch block check and handle. the exception.JdbcOdbcConnectivity.java
rno libno 1 101 2 102 3 103 4 104 5 105 6 106 7 107 8 108
Rs. 20,000 US$ 300
Today: Rs. 10,000 US$150
Course Duration: 30 hrs
Posted on: November 19, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles