In this Tutorial we help you to understand an example from JDBC Next.



The Tutorial help in understanding JDBC Next. The program describe a code that gives you the number of rows in the table. The code include a class JDBC Next, Inside the class we have a main method that follows the list of steps to get the number of rows in a table -

  Import a package java.sql.* : This package provides you set of all classes that enables a network interface between the front end and back end database. Loading a driver is the next step to be followed by calling a class.forName( ),this accept a driver class as argument.

 DriverManager.getConnection( ) : The Driver Manager call a get Connection method ,which return a connection object, this object built a connection between url-backend.

 con.createStatement ( ) : This is used to create sql object. An object of connection class is used to send and execute the sql queries in database.

  execute Query( ) : This is used to retrieve the record set from the database and the retrieve record set is assigned in Result Set. The select statement is used to retrieve the record set from table.

Finally the rs.next ( ) is used to retrieve the next sequence element in the series.

The println print the number of row as output.


import java.sql.*;

public class JdbcNext {

  static public final String driver = "com.mysql.jdbc.Driver";
  static public final String connection =
  static public final String user = "root";
  static public final String password = "root";

  public static void main(String args[]) {

  try {
  Connection con =
 user, password);

  Statement st = con.createStatement();

  String sql = "select * from person";
  ResultSet rs = st.executeQuery(sql);
  int i=0;
  System.out.println("No. of Row :"+i);
  catch (Exception e) {


No. of Row :2

Download code



We have 1000s of tutorials on our website. Search Tutorials tutorials on our website.

Share on Google+Share on Google+


Posted on: November 18, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles



Discuss: JDBC Next  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image