Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package databasetest1;
- import java.sql.*;
- public class Connectiontest1 {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- try{
- //step1 load the driver class
- Class.forName("oracle.jdbc.driver.OracleDriver");
- //step2 create the connection object
- Connection con=DriverManager.getConnection( "jdbc:oracle:thin:@172.20.20.168:1521:ORCL","scott","tiger");
- //step3 create the statement object
- Statement stmt=con.createStatement();
- //step4 execute query
- PreparedStatement stmt1=con.prepareStatement("insert into EMPPPP values(?,?)");
- PreparedStatement stmt2=con.prepareStatement("Delete from EMPPPP where id=4");
- stmt1.setInt(1,1);//1 specifies the first parameter in the query
- stmt1.setString(2,"hello");
- int i=stmt1.executeUpdate();
- int i1=stmt2.executeUpdate();
- System.out.println(i+" records inserted");
- ResultSet rs=stmt.executeQuery("select * from EMPPPP");
- while(rs.next())
- System.out.println(rs.getString(1)+" "+rs.getString(2));
- //step5 close the connection object
- //con.close();
- }catch(Exception e){ System.out.println(e);}
- }
- }
Add Comment
Please, Sign In to add comment