Advertisement
Guest User

Untitled

a guest
Jul 7th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.38 KB | None | 0 0
  1. import java.sql.Connection;
  2. import java.sql.ResultSet;
  3. import java.sql.SQLException;
  4. import java.sql.Statement;
  5. import oracle.jdbc.pool.OracleDataSource;
  6.  
  7. /**
  8.  *
  9.  * @author Rahman YAZGAN
  10.  *
  11.  * Oracle 10g Express
  12.  * jdbcUrl = "jdbc:oracle:thin:hr/hr@localhost:1521/XE"
  13.  *
  14.  */
  15. public class OracleDBConnection {
  16.     public static void main(String[] args) throws SQLException {
  17.         String jdbcUrl, userid, password, query;
  18.         Connection connection;
  19.         Statement statement;
  20.         ResultSet resultSet;
  21.        
  22.         jdbcUrl = "jdbc:oracle:thin:hr/hr@localhost:1521/XE";
  23.         userid = "user";
  24.         password = "1111";
  25.                
  26.         OracleDataSource dataSource = new OracleDataSource();
  27.         dataSource.setURL(jdbcUrl);
  28.         connection = dataSource.getConnection(userid, password);
  29.         statement = connection.createStatement();
  30.  
  31.         query = "INSERT INTO UYELER (ID, AD, SOYAD) VALUES (NULL, 'MEHMET', 'BİLİR')";
  32.         resultSet = statement.executeQuery(query);
  33.  
  34.         query = "SELECT * FROM UYELER";
  35.         resultSet = statement.executeQuery(query);
  36.  
  37.         String column[] = {"ID", "AD", "SOYAD"};
  38.  
  39.         while (resultSet.next()) {
  40.             for (int i = 1; i <= column.length; i++) {
  41.                 System.out.print(resultSet.getString(i) + " ");
  42.             }
  43.             System.out.println("");
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement