You are on page 1of 1

C:\oraclexe\app\oracle\product\10.2.

0\server\jdbc\lib

Creating a table in JDBC:

Statement stmt = con.createStatement


("create table product (pid number(4) primary key,pname varchar2(20),price
number(10,2))";

int n = stmt.executeUpdate(vsql);
----------------------
Inserting a single row into a table:

Statement st=con.createStatement();
int i=0;
i=st.executeUpdate("insert into product values(107,'hhh',10.9)");
-------------------------------
Update a record in table using JDBC:
Statement st=con.createStatement();
int i=0;
i=st.executeUpdate("update product set price=123.45 where pid=107");
------------------------------------
Inserting multiple number of records into a table using JDBC:

String vsql = "insert into product values(?,?,?)";

PreparedStatement pstmt = con.prepareStatement(vsql);

Scanner sc = new Scanner(System.in);


System.out.print("Enter how records:");
int nr = sc.nextInt();
System.out.println("No of record you need to enter:"+nr);
for(int i=1;i<=nr;i++){
System.out.println("Enter product id:");
id = sc.nextInt();
System.out.println("Enter product name:");
name = sc.next() + sc.nextLine();
System.out.println("Enter product price:");
price = sc.nextDouble();

//storing data into positional parameters


pstmt.setInt(1,id);
pstmt.setString(2,name);
pstmt.setDouble(3,price);

//execute the query


pstmt.executeUpdate();

You might also like