Followers

JDBC: selection using PreParedStatement

package com.pack1;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class SelectPrePared {
   
     public static void main(String[] args) throws Exception
    {
        Connection con = null;
        ResultSet rs = null;
     
            Class.forName("org.apache.derby.jdbc.ClientDriver");
            String url = "jdbc:derby://localhost:1527/hari";
            con = DriverManager.getConnection(url, "app","app");
            String query = "select ENO, NAME,SALARY from MYEMP where SALARY <= ?";
            PreparedStatement pstmt = con.prepareStatement(query);
           pstmt.setFloat(1, 30000);
           rs = pstmt.executeQuery();
           while(rs.next()){
           System.out.println(rs.getInt(1)+" "+rs.getString("NAME")+" "+rs.getFloat(3));
           }
         
   
    }
   
}

No comments:

Post a Comment