JDBC Get Int

In this tutorial we want to describe you a code that help in understanding JDBC Get Int.

JDBC Get Int


The  get Byte, get Short, get Long, get Float, get Double, getBigDecimal, get Boolean, get String, get Object is readable by Get Int in Java.

Understand with Example

The Tutorial illustrates an example from JDBC Get Int.In this Tutorial, the program explain you a JDBC code that connect the front end application to the backend database. The code include the sql queries that return you the integer and retrieve the element from the database. For this we have a class Jdbc Get Int, Inside the main method driver loading is done by calling a class.forname(  ) ,that accept driver class as argument.





  Method    Description


Return you an object of connection, built  a connection between url and database.

con.createStatement( )

Return you a sql object, The return object is used to send and execute the query in database.

executeQuery( )

Return you a result set, This result set contain a set of retrieved element from a table

getInt( )

Return you the retrieve the value of specified column in the current row of the result set object as int.

The rs.next( ) return you the next element in the series. Finally the println print the respective id on the output. The con.close ( ) closed connection with database. 

Finally the println print the respective id in the output. In case an exception occurred in try block, the subsequent catch block check and caught the exception.


import java.sql.*;

public class JdbcGetInt {

    public static void main(String args[]) {

        Connection con = null;
        Statement st = null;
        ResultSet rs = null;

        String url = "jdbc:mysql://localhost:3306/";
        String db = "komal";
        String driver = "com.mysql.jdbc.Driver";
        String user = "root";
        String pass = "root";

        try {
            con = DriverManager.getConnection(url + db, user, pass);
            st = con.createStatement();

            String sql = "select * from person";
            rs = st.executeQuery(sql);
            while (rs.next()) {

        } catch (Exception e) {


Id	Name
1	Girish
2	komal

Download code