Professional Documents
Culture Documents
VR Ajp 18
VR Ajp 18
VR Ajp 18
Program:-
import java.sql.*;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("connecting to database");
Connection con=DriverManager.getConnection("jdbc:odbc:nespdsn");
System.out.println("Connected to database");
Statement s1=con.createStatement();
ResultSet rs=s1.executeQuery(s);
while(rs.next()){
System.out.println(rs.getInt("ID"));
System.out.println(rs.getString("Name"));
System.out.println(rs.getInt("Percentage"));
con.close();
catch(Exception e){
System.out.println(e);
Output:-
Practical No. 19: Write a Program to demonstarte the use of
PreparedStatement and ResultSet interface.
Program:-
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Connecting to Database");
Connection con=DriverManager.getConnection("jdbc:odbc:nespdsn");
System.out.println("Connected to Database");
PreparedStatement st=con.prepareStatement(s);
st.executeUpdate();
con.close();
}
catch(Exception e){
System.out.println("Connection error");
Output:-
Practical No. 20: Write a program to update and delete a record
from a database table.
1.Develop a program to update name of student from Jack to John.
Program:-
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Connecting to Database");
Connection con=DriverManager.getConnection("jdbc:odbc:nespdsn");
System.out.println("Connected to Database");
PreparedStatement st=con.prepareStatement(s);
st.executeUpdate();
con.close();
catch(Exception e){
System.out.println("Connection error");
Output:-
2.Develop a program to delete all record for product whose “price is greater
Program:-
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Connecting to Database");
Connection con=DriverManager.getConnection("jdbc:odbc:nespdsn");
System.out.println("Connected to Database");
PreparedStatement st=con.prepareStatement(s);
st.executeUpdate();
con.close();
catch(Exception e){
System.out.println(e);
Output:-