22 Desember 2011
JDBC_1
package PBOproject;
import java.sql.*;
import oracle.jdbc.pool.OracleDataSource;
public class JDBCSekre {
String jdbcUrl = "jdbc:oracle:thin:@localhost:1521:xe";
String userid = "hr";
String password = "hr";
Connection conn;
Statement stmt;
ResultSet rset;
String query;
String sqlString;
public JDBCSekre(){
}
public void getDBConnection() throws SQLException {
try{OracleDataSource ds;
ds = new OracleDataSource();
ds.setURL(jdbcUrl);
conn = ds.getConnection(userid, password);
System.out.println("Koneksi berhasil");
}catch (SQLException ex) {
System.out.println("Masih belum konek");
// OracleDataSource ds;
// ds = new OracleDataSource();
// ds.setURL(jdbcUrl);
// conn = ds.getConnection(userid, password);
}
}
public ResultSet getAllSekretariat() throws SQLException {
getDBConnection();
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
query = "Select * FROM Sekretariat";
System.out.println("\nExecuting query: " + query);
rset = stmt.executeQuery(query);
return rset;
}
public static void main(String[] args) throws SQLException {
JDBCSekre ld = new JDBCSekre();
ResultSet rset = ld.getAllSekretariat();
while (rset.next()) {
System.out.println(rset.getInt(1) + " "
+ rset.getString(2) + " "
+ rset.getString(3) + " "
+ rset.getString(4) + " "
+ rset.getString(5) + " "
+ rset.getString(6) + " "
+ rset.getString(7) + " "
+ rset.getString(8));
}
ld.conn.close();
}
}
Langganan:
Posting Komentar (Atom)
Tidak ada komentar:
Posting Komentar