ResultSet in Java Example Program

By | December 26, 2010
ResultSet in Java example JDBC Concepts. This Java ResultSet DB (database) example describes the basic operations performed on the JDBC ResultSet database connectivity code.
ResultSet in Java example JDBC Concepts. This Java ResultSet DB (database) example describes the basic operations performed on the JDBC ResultSet database connectivity code.In this example you will learn about how to write java code for ResultSet with oracle database.

Program:

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class ResultSetDemo {
public static void main(String args[]){
Connection con=null;
Statement st = null;
try {
Class.forName(“oracle.jdbc.driver.OracleDriver”);
con=DriverManager.getConnection(“jdbc:oracle:thin:@localhost:1521:ORCL”,”scott”,”tiger”);
st = con.createStatement();
ResultSet rs = st.executeQuery(“select * from eshusoft”);
while(rs.next()){
String userName= rs.getString(1);
String password = rs.getString(2);
System.out.println(“userName: “+userName);
System.out.println(“password: “+password);
}
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

Result:

username :  myuser
password : mypwd

Leave a Reply

Your email address will not be published. Required fields are marked *