Monday, January 13, 2014

Java JDBC programming Example 4

//Note: create  a DSN in the name of sql that is pointing to the table name limbs in the database with three String fields





//FINDING  NO OF RECORDS
import java.sql.*;
import java.net.*;
class Jdbc4{
public static void main(String...arg) throws Exception{
System.out.println(InetAddress.getLocalHost());
         Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
         Connection c =  DriverManager.getConnection("jdbc:odbc:sql");
         Statement  st = c.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
  ResultSet.CONCUR_UPDATABLE);
         ResultSet r = st.executeQuery("select * from limbs");
// finding no of  records   one way
          r.last();
          int norec = r.getRow();
        System.out.println("No of records  "+norec);
       
// finding no of  records   another  way
r = st.executeQuery("select count(*) FROM limbs");
r.next();
int count = r.getInt(1);
      System.out.println("No of records  "+count);
      r.close();
      st.close();
      c.close();
}
}


Post a Comment