JDBC

JDBC Projects

JDBC Project 1

adplus-dvertising
JDBC Using Statement example – Insert a record
Previous Home Next
/*This program shows you how to insert the data in
the database table using JDBC Statement.*/
package r4r;
import java.sql.*;
import java.util.*;
public class InsertData 
{
public static void main(String[] args) {
try
{
Scanner s=new Scanner(System.in);
int sal=s.nextInt();
s.nextLine();
/*System.out.println("Enter your name:-");
String s1=s.nextLine();
System.out.println("Enter the id:-");
int i=s.nextInt();
s.nextLine();
System.out.println("Enter the city:-");
String c=s.nextLine();
System.out.println("Enter sex:-");
String se=s.nextLine();*/
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection
("jdbc:oracle:thin:@localhost:1521:xe","system","oracle");
Statement stmt=con.createStatement();
stmt.executeUpdate("insert into gaurav1 (salary) values" +
"('"+sal+"')");
System.out.println("successfully inserted");
con.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}

output:

Enter your name:-
gaurav
Enter the id:-
1
Enter the city:-
noida
Enter sex:-
m
successfully inserted
Previous Home Next