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
|
/*
* Here we will learn to fetch the result from result set.
*/
package jbt;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class RetrieveValueFromResultSet {
public static void main(String[] args) throws SQLException,
ClassNotFoundException {
Class.forName("oracle.jdbc.OracleDriver");
String serverName = "12.2.6.4";
String portNumber = "1541";
String sid = "SID";
String url = "jdbc:oracle:thin:@" + serverName + ":" + portNumber + ":"
+ sid;
String username = "dba";
String password = "123";
Connection conn = DriverManager.getConnection(url, username, password);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from jbt_table");
int columnSize = rs.getMetaData().getColumnCount();
System.out.println("Number of Columns in Table : "+columnSize);
while (rs.next()) {
for (int i = 1; i <= columnSize; i++) {
System.out.print(rs.getString(i)+" ");
}
System.out.println();
}
}
}
|