JDBC

JDBC Projects

JDBC Project 1

JDBC Using PreparedStatement example Update a record
Previous Home Next
/* This program shows you how to update the data in 
the database table using JDBC PreparedStatement .
In this you update the name on the giving id.*/

package r4r;
import java.sql.*;
import java.util.*;
public class UpdateData 
{
public static void main(String[] args) 
{
try
{
Scanner in=new Scanner(System.in);
System.out.println("enter the name:-");
String n=in.nextLine();
System.out.println("enter the id:-");
int i=in.nextInt();
in.nextLine();
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection
("jdbc:oracle:thin:@localhost:1521:xe","system","oracle");
PreparedStatement stmt=con.prepareStatement("update user5 
set name=? where id=?");
stmt.setString(1, n);
stmt.setInt(2, i);
stmt.executeQuery();
System.out.println("successfully updated");
con.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}

 

output:

enter the name:-
Ajeet
enter the id:-
12
successfully updated
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: