Sponsered Links
Categories
Sponsered Links

JDBC Date Format Example

 

This is a simple  Date Format Example.

import java.sql.*;
import java.io.*;
import java.util.Date;
import java.text.DateFormat;

class DateExample {
    public static void main( String argv[] ) {
        try {
            Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
            String url = "jdbc:odbc:db1";
            Connection dbcon = DriverManager.getConnection (url, "", "");
            Statement smnt = dbcon.createStatement();
            Date dates = new Date();
            long seconds = dates.getTime();
            String start_time = DateFormat.getTimeInstance().format( dates );
            System.out.println( "Start Time: " + start_time );
            int n = 1;
            String queries = "select * from emp1 where salary = ";
            String queryString = queries + n;
            ResultSet res = smnt.executeQuery( queryString );
            boolean more = res.next();
            for (; n < 2000 && more ; n++ ) {
                queryString = queries + n;
                res = smnt.executeQuery( queryString );
                more = res.next();
            }
            Date end_date = new Date();
            long end_second = end_date.getTime();
            String end_time = DateFormat.getTimeInstance().format( end_date );
            System.out.println( "End Time:" + end_time );
            seconds = (end_second - seconds)/1000;
            System.out.println( "Elapsed time: " + seconds + " seconds for " + n + " records.");
        }catch (java.lang.Exception ex) {
            System.out.println( "** Error on data insert. ** " );
            ex.printStackTrace ();
        }
    }
}

 
 
Sponsered Links
Latest Updates
 
All Content of this site is for learning only. We do not warrant the correctness of its content. The risk from using it lies entirely with the user. While using this site, you agree to have read and accepted our terms of use and privacy policy.
Copyright © 2009 JSPSERVLETTUTORIAL.INFO All Right Reserved