JDBC Notes
JDBC Notes
JDBC Notes
show user;
open command prompt to check whether oracle type iv driver exist or not
javap oracle.jdbc.driver.OracleDriver
javac DriverTest.java
java DriverTest
// InsertDemo.java
import java.sql.*;
public class InsertDemo {
public static void main(String rags[]) throws ClassNotFoundException,
SQLException {
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE", "kesava",
"kesava");
Statement stmt=con.createStatement();
int i=stmt.executeUpdate("insert into student values (1, '20195A1234',
'ABC')");
System.out.println(i+" row inserted");
}
}
// DynamicInsertDemo.java
import java.sql.*;
import java.util.*;
public class DynamicInsertDemo {
public static void main(String rags[]) throws ClassNotFoundException,
SQLException {
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE", "kesava",
"kesava");
Statement stmt=con.createStatement();
Scanner sc=new Scanner(System.in);
int sno=sc.nextInt();
String rollno=sc.next();
String name=sc.next();
int i=stmt.executeUpdate("insert into student values
("+sno+",'"+rollno+"','"+name+"')");
System.out.println(i+" row inserted");
}
}