100% found this document useful (1 vote)
1K views6 pages

Ajp Practical 19

The document contains 3 JDBC programs written by a student: 1) A program to update a row in a database table by updating the product ID where the price is 1000. 2) A program to retrieve data from a result set by connecting to a database and querying a table to print out student details. 3) A program to update a record in a database table by updating the student name where the roll number is 105.

Uploaded by

nstrnsdtn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
1K views6 pages

Ajp Practical 19

The document contains 3 JDBC programs written by a student: 1) A program to update a row in a database table by updating the product ID where the price is 1000. 2) A program to retrieve data from a result set by connecting to a database and querying a table to print out student details. 3) A program to update a record in a database table by updating the student name where the roll number is 105.

Uploaded by

nstrnsdtn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Name : Ayush Maroti Wadje Roll no. : 76 Practical no.

: 19

1.Write a Program to update row of table from Msbte database using


database

import java.sql.*;
public class MSBTE
{
public static void main(String[] args){
try{
Connection con =
DriverManager.getConnection("jdbc:ucanaccess://D://MSBTE.accdb");
Statement s = con.createStatement();
s.execute("update msbte set P_id='P1237' where price=1000");
s.execute("select * from msbte");
ResultSet rs = s.getResultSet();
if (rs != null){
while ( rs.next() ) {
System.out.println(" " );
System.out.println("Id of the product: " + rs.getString(1) );
System.out.println("Price of product: " + rs.getString(2) );
System.out.println(" " );}
s.close();
con.close();}}
catch (Exception err){
System.out.println("ERROR: " +err);
}
}
}
Output :
1. Develop a JDBC program to retrieve data from resultset

import java.sql.*;
public class Retrieve
{
public static void main(String[] args){
try{
Connection con =
DriverManager.getConnection("jdbc:ucanaccess://D://student.accdb");
Statement st = con.createStatement();
st.execute("select * from Stud_Data");
ResultSet rs = st.getResultSet();
if (rs != null){
while ( rs.next() ) {
System.out.println(" " );
System.out.println("Roll No: " + rs.getString(1) );
System.out.println("First Name: " + rs.getString(2) );
System.out.println("Branch : " + rs.getString(1) );
System.out.println("Percentage : " + rs.getString(2) );
System.out.println(" " );}
st.close();
con.close();}}
catch (Exception err){
System.out.println("ERROR : 00 " +err);
}
}
}
Output :
2. Develop a program to update a record in database table

import java.sql.*;
public class PR_AD19
{
public static void main(String[] args){
try{
Connection con =
DriverManager.getConnection("jdbc:ucanaccess://D://student.accdb");
Statement s = con.createStatement();
s.execute("update Stud_Data set Stud_Name ='Ayush' where Roll_No=105 ");
s.execute("select * from Student_Data");
ResultSet rs = s.getResultSet();
if (rs != null){
while ( rs.next() ) {
System.out.println(" " );
System.out.println("Name : " + rs.getString(1) );
System.out.println(" Dept : " + rs.getString(2) );
System.out.println(" " );}
s.close();
con.close(); }}
catch (Exception err){ System.out.println("ERROR: " + err);
}
}
}

Output :

You might also like