import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class First {
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
Connection con=null;
Statement stmt=null;
try {
DriverManager.registerDriver(new com.mysql.jdbc.Driver());
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");
stmt = con.createStatement();
stmt.setFetchSize(1);
long t1 = System.currentTimeMillis();
ResultSet rs = stmt.executeQuery("select * from first");
while(rs.next()){
System.out.println(rs.getInt(1));
}
long t2 = System.currentTimeMillis();
//System.out.println("The time is");
System.out.println("The time is " +(t2-t1));
con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
output:-
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
The time is 3
No comments:
Post a Comment