R4R Team working to provide free of cost for experienced and freshers

Tutorials | Examples|Interview Questions and Answers|Java Tutorials| C Tutorials | C++ Tutorials | Spring Tutorials| Hibernate Tutorials | JSP Tutorials | Servelets Tutorials| C# Tutorials | PHP Tutorials etc , Basics | Download Software | Data Types | Variables | Constant | Storage & Classes | Operators | Decisions Making | Loops | Functions| Numbers | Arrays | Pointers | String | Datastructure | Expressions | Preprocessor Statement | I/O | Exception Handling | OOPs Tutorial | Classes and object |C++ Inheritance Overloading | Polymorphism | Abstraction | Encapsulation | Interfaces | Multithreading etc

JDBC

JDBC Projects

JDBC Project 1

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