Skip to main content

JDBC FAQ Part14

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);
                        }
            }
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));
                                    }
                        }
            }

Comments

Popular posts from this blog

దోసకాయ పూర్ణం | cucumber curry

How to merge Objects in Javascript

 let person = {     firstName: 'Rocky',     lastName: 'g',     age: 23 }; let job = {     jobTitle: 'Angular Developer',     location: 'UK' }; let employee = {     ...person,     ...job }; console.log(employee);

క్యారెట్ ఊరగాయ | carrot pickle