Q) Develop a JDBC application that retrieves all the accounts information from the db and displays on the console using JDBC approach (not JDBC – ODBC approach)
A)
import java.sql.*;
class RealAccount1 {
public static void main(String[] args) {
Class.forName("Oracle.jdbc.odbc.OracleDriver");
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost1521:server","scott","tiger");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("SELECT * FROM ACCOUNT");
while(rs.next()){
System.out.println("Accno :"+rs.getInt(1));
System.out.println("A/C holder name :"+rs.getString(2));
}
rs.close();
st.close();
con.close();
}
}
Comments
Post a Comment