Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) {
- // TODO code application logic here
- Connection conn = null;
- try{
- String driverName = "oracle.jdbc.driver.OracleDriver";
- Class.forName(driverName);
- String serverName = "localhost";
- String serverPort = "1521";
- String sid = "XE";
- String url = "jdbc:oracle:thin:@" + serverName + ":" + serverPort + ":" + sid;
- String username = "SYSTEM";
- String password = "Batman1997";
- conn = DriverManager.getConnection(url, username, password);
- System.out.println("Sucesso");
- }catch(ClassNotFoundException e){
- System.out.println("could not find the DB driver " + e.getMessage());
- }catch(SQLException e){
- System.out.println("Could not connect to the database " + e.getMessage());
- }
- //vai tentar buscar os dados
- try{
- System.out.println("rfr");
- Statement st = conn.createStatement();
- ResultSet rs = st.executeQuery("select * from TestingTable");
- while(rs.next()){
- int num = rs.getInt(1);
- String name = rs.getString(2).toString();
- System.out.println("" + num + " " + name);
- }
- }catch(Exception e){
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement