JDBC

JDBC Projects

JDBC Project 1

JDBC Using Statement example Batch Update
Previous Home Next
/* This example shows you how to insert few records in 
batch process via JDBC statement.*/

package r4r;
import java.sql.*;
import java.util.*;
public class BatchUpdate {
public static void main(String[] args) 
{
try
{
Scanner in=new Scanner(System.in);
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection
("jdbc:oracle:thin:@localhost:1521:xe","system","oracle");
Statement stmt=con.createStatement();
while(true)
{
System.out.println("Enter name:-");
String n=in.nextLine();
System.out.println("Enter id:-");
int i=in.nextInt();
in.nextLine();
System.out.println("Enter city:-");
String c=in.nextLine();
System.out.println("Enter sex:-");
String se=in.nextLine();
stmt.addBatch("insert into user5 values('"+n+"','"+i+"','"+c+"','"+se+"')");
System.out.println("Want to save more object,YES/NO");
String ans=in.nextLine();
if(ans.equals("no"))
break;
}
stmt.executeBatch();
System.out.println("successfully added batch");
con.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}

 

output:

Enter name:-
harsh
Enter id:-
5
Enter city:-
delhi
Enter sex:-
m
Want to save more object,YES/NO
yes

Enter name:-
rajesh
Enter id:-
7
Enter city:-
noida
Enter sex:-
m
Want to save more object,YES/NO
no
successfully added batch
Previous Home Next

Tolal:0 Click:

Show All Comments

Did not find what you were looking for leave your name and message. We will revert within 24 hours
Name:
eMail:
Comment / Feedback: