JDBC Fetch
The Tutorial describe you a code that fetch the elements from a database. In this Tutorial we want to describe you an example from Jdbc Fetch. In this program code, the System.println print the fetch data from database. The code illustrates a class Jdbc Fetch, Inside the main method we have the list of steps to be followed -
The first step is to import a java.sql.* ,this provides you a network interface helps you in communicating between the front end Java application and the backend Loading a driver follows the next step, by calling a class.forName ( ) with driver class passed as argument.
DriverManger.getConnection( ) :This method return you a connection object, This method is used to built a connection between the url and database. The createStatement ( ) return you a statement object, this statement is used to execute and send SQL query in the database.The Statement object call execute Query ( ),The method is used to
fetch the record set from employee table, that accept sql passed as an
argument.
Finally on execution the println print the
element from database using getString ( ) from the record set.
getString(
):The method return and retrieves the value of the specified column
name in the current row of this object as a String in
the Java programming language.
JdbcFetch.java
|
Output
Girish Tewari Rohini Indian Komal Singh Rohini Indian Sandeep kumar Rohini Indian Amit Singh Rohini Indian Girish Tewari Rohini Indian Darshan Tewari Rohini Indian |