ResultSet findColumn Example
ResultSet Interface findColumn example. This example shows you how to use findColumn method.
ResultSet Interface findColumn example. int findColumn(String columnLabel) throws SQLException Maps the given ResultSet column label to its ResultSet column index.
Here is the code
/*
* @ # FindColumn.java
* A class repersenting use to findColumn method
* of ResultSet in java.sql package
* version 01 July 2008
* author Rose India
*/
import java.sql.*;
public class FindColumn {
public static void main(String[] args) throws Exception {
Connection con = null;
Statement st = null;
ResultSet rs = null;
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://192.168.10.59:3306/";
String db = "Student";
Class.forName(driver);
con = DriverManager.getConnection(url + db, "root", "root");
try {
String sql = "Select * from stu_info";
st = con.createStatement();
rs = st.executeQuery(sql);
System.out.println("Column Name its ResultSet column index "
+ rs.findColumn("name"));
} catch (Exception e) {
System.out.println("SQL statement is not executed!");
System.out.println(e.toString());
}
}
} |
Output
| Column Name its ResultSet column index 2 |
|