From fdecd814f47a98e653fdea46806f3bea465d667c Mon Sep 17 00:00:00 2001 From: LOVE1668 <112742418+LOVE1668@users.noreply.github.com> Date: Sat, 11 Mar 2023 19:14:36 +0530 Subject: [PATCH] hueheurandi --- Advance_Java/Jdbc2.java | 52 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 Advance_Java/Jdbc2.java diff --git a/Advance_Java/Jdbc2.java b/Advance_Java/Jdbc2.java new file mode 100644 index 0000000..663a427 --- /dev/null +++ b/Advance_Java/Jdbc2.java @@ -0,0 +1,52 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Main.java to edit this template + */ +package jdbc2; + +import java.sql.*; +/** + * + * @author hp + */ + + +public class Jdbc2 { + + /** + * @param args the command line arguments + * @throws java.lang.ClassNotFoundException + */ + public static void main(String[] args) throws ClassNotFoundException{ + // TODO code application logic here + + String query ="select * from ADITYA.STUDENT"; + Class.forName("oracle.jdbc.driver.OracleDriver"); + + try (Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","system","system") ){ + + //Insert + PreparedStatement ins=conn.prepareStatement("Insert into ADITYA.STUDENT values('3','Soham')"); + ins.executeUpdate(); + + //Update + PreparedStatement upd=conn.prepareStatement("update ADITYA.STUDENT set name='loved' where name='love'"); + upd.executeUpdate(); + + PreparedStatement del=conn.prepareStatement("delete from ADITYA.STUDENT where id='1'"); + del.executeUpdate(); + + Statement state=conn.createStatement(); + ResultSet rs=state.executeQuery(query); + while(rs.next()){ + System.out.println(rs.getString(1)+rs.getString(2)); + } + + + + }catch(Exception e){ + e.printStackTrace(); + } + } + +}