MCQs Test!! VB Basic Test !! Essentials of VB !! Creating User Services !! function !! Anatomy !! GK March-2019 !! DATA TYPES IN JAVA !! Classes ,Constructor ,Methods,Inheritance !! Ecology-I !! Biology 2019 !! Gk april 2019 !! Biology (living world) !! Plant anatomy !! CELL STRUCTURES AND FUNCTION !! General biology !! Human physiology !! Data structure !! Ecology-II !! GK TEST !! Reproduction in plants !! Human reproduction !! The ABC of C !! Operating system set1 !! Operating system set2 !! Gk and current affairs !! Animal kingdom !! Number system !! Animal kingdom-II !! Gk TEST-III !! Number series !! Microorganisms !! Interview question in c !! Time and Work !! Percentage !! General history !! Average !! Cells !! Locomotion and Movement !! paging !! Bacteriology !! Page replacement policy !! Secondary memory and Disk scheduling !! Introduction of Nervous System and neurons !! Plant harmones !! Transport and Mineral Nutrition in Plants !! Neurotransmitters !! Modern Indian History !! Photosynthesis in Plants !! Modern Indian History-II !! Plant respiration !! Environment & Biodiversity !! Environment & Biodiversity - II !! Algae, Bryophytes, Pteridophytes !! Area !! Cricket !! Days of the Year (India and the World) !! Plant Pathology - I !! Indian Transport System !! Plant Pathology - II !! Aptitude !! Biology !! Botany !! C language !! Computer Science !! Core Java !! Gate !! GK !! Mysql !! Operating system !! Physics !! VB-Visual Basic !! Zoology

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