31: how to update the database through PreparedStatement object.
import java.sql.*;
public class PreparedUpdateEx
{
public static void main(String[] args)throws Exception
{
Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);
Connection con = DriverMadoeer.getConnection(“jdbc:odbc:doe”,”system”,”jhon”);
PreparedStatement pst = con.prepareStatement(“update emp1 set esal = esal+? Where esal<?”);
Pst.setInt(1,500);
Pst.setFloat(2,10000.0f);
Int count = pst.executeUpdate();
System.out.println(“no. of records updated:”+count);
}
}
public class PreparedUpdateEx
{
public static void main(String[] args)throws Exception
{
Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);
Connection con = DriverMadoeer.getConnection(“jdbc:odbc:doe”,”system”,”jhon”);
PreparedStatement pst = con.prepareStatement(“update emp1 set esal = esal+? Where esal<?”);
Pst.setInt(1,500);
Pst.setFloat(2,10000.0f);
Int count = pst.executeUpdate();
System.out.println(“no. of records updated:”+count);
}
}
32:how to fetch the data from database through PreparedStatement object.
import java.sql.*;
public class UpdateResEx
{
public static void main(String[] args)throws Exception
{
Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);
Connection con = DriverMadoeer.getConnection(“jdbc:odbc:doe”,”system”,”jhon”);
PreparedStatement pst = con.prepareStatement(“select * from emp1 where esal<=?”);
Pst.setFloat(1,10000.0f);
ResultSet rs = pst.executeQuery();
System.out.println(“ENO ENAME ESAL EADDR”);
System.out.println(“******************************”);
While(rs.next())
{
System.out.println(rs.getInt(1)+” “+rs.getString(2)+” “+rs.getFloat(3)+” “+rs.getString(4));
}
}
}
public class UpdateResEx
{
public static void main(String[] args)throws Exception
{
Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);
Connection con = DriverMadoeer.getConnection(“jdbc:odbc:doe”,”system”,”jhon”);
PreparedStatement pst = con.prepareStatement(“select * from emp1 where esal<=?”);
Pst.setFloat(1,10000.0f);
ResultSet rs = pst.executeQuery();
System.out.println(“ENO ENAME ESAL EADDR”);
System.out.println(“******************************”);
While(rs.next())
{
System.out.println(rs.getInt(1)+” “+rs.getString(2)+” “+rs.getFloat(3)+” “+rs.getString(4));
}
}
}
Comments
Post a Comment