Online Hibernate Training just in Rs. 1000

One week online training in Hibernate ORM framework. Learn Hibernate Framework and enhance your skills. Best Online Hibernate training at 90% discount. Join Now!! Offer is valid Only for limited Period!!! Online Training

JDBC Next

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

Ads

Tutorials   
JDBC Video Tutorial: Create, Read, Update and Delete (CRUD) Operation examples JDBC Video tutorial - How to read Data from MySQL Database? JDBC Video tutorial - How to delete Data in a MySQL Database? Solving java.lang.ClassNotFoundException: com.mysql.jdbc.Driver exception JDBC Video tutorial - How to update Data in a MySQL Database? JDBC Video Tutorial- How to insert data into MySQL database table? JDBC Video Tutorial: How to download JDBC Driver for MySQL? JDBC Tutorial - Writing first JDBC example and running in Eclipse Java Cross Join MySQL Database Connectivity Example In Java Change Column Name in MySQL Java Mysql Connection Example JDBC ODBC Connection In Java ResultSet In Java Prepared Statement Example JdbcRowSet interface Java JdbcRowSet Example First Step towards JDBC! JDBC Training, Learn JDBC yourself Jdbc Get Column Names JDBC Example with MySQL JDBC Prepared Statement Update JDBC Prepared Statement Insert JDBC Prepared Statement Example JDBC Prepared statement Close JDBC Prepared Statement Addbatch JDBC Nested Resultset JDBC-Odbc Connection JDBC-Odbc Connectivity JDBC Insert Preparedstatement JDBC Insert Null JDBC Get Metadata JDBC Insert Record Jdbc Insert Statement JDBC Meta Data Get tables Jdbc Mysql Connection String Jdbc Mysql Connection Url JDBC Next Jdbc Get Connection JDBC Get Int JDBC Exception JDBC Get Row Count JDBC Functions JDBC Fetch JDBC Execute Update Example JDBC Execute Statement JDBC Execute Query JDBC Drive For Mysql JDBC Connectivity Code In Java JDBC connection timeout
Ads

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.

JdbcNext.java


import java.sql.*;

public class JdbcNext {

  static public final String driver = "com.mysql.jdbc.Driver";
  static public final String connection =
  "jdbc:mysql://localhost:3306/komal";
  static public final String user = "root";
  static public final String password = "root";

  public static void main(String args[]) {

  try {
  Class.forName(driver);
  Connection con =
 DriverManager.getConnection(connection, 
 user, password);

  Statement st = con.createStatement();

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

Output

No. of Row :2

Download code

Advertisements

Share on Google+Share on Google+

JDBC Next

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

Advertisements

Ads
 

Discuss: JDBC Next  

Post your Comment


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

Ads

 

Ads