Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- public class Database {
- public static void main(String[] args) {
- try {
- // step1 load the driver class
- Class.forName("oracle.jdbc.driver.OracleDriver");
- // step2 create the connection object
- Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "system", "system");
- // step3 create the statement object
- Statement stmt = con.createStatement();
- // For inserting Data
- // ----------------------
- // Statement insertQuery = con.createStatement();
- // insertQuery.executeQuery("INSERT INTO emp (ID, Name, Age) VALUES (3, 'Vikas', 23)");
- // ----------------------
- // step4 execute query
- ResultSet rs;
- rs = stmt.executeQuery("SELECT * FROM emp");
- while (rs.next()) {
- System.out.println(rs.getInt(1) + " " + rs.getString(2) + " " + rs.getInt(3));
- }
- // step5 close the connection object
- con.close();
- }
- catch (Exception e) {
- System.out.println(e);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement