Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public boolean keyExists(BigDecimal primaryKey, String column) throws SQLException {
- Connection con = null;
- PreparedStatement ps= null;
- ResultSet rs=null;
- int count=0;
- try {
- con = DBConnect.getConnection();
- if (column.equalsIgnoreCase("product_id")) {
- column="product_id";
- ps=con.prepareStatement("select count(*) from CSC342.Product where product_id=?");
- } else if (column.equalsIgnoreCase("material_id")) {
- column="material_id";
- ps=con.prepareStatement("select count(*) from CSC342.Raw_Material where material_id=?");
- } else {
- return false;
- }
- //ps.setString(1,column);
- ps.setBigDecimal(1,primaryKey);
- rs=ps.executeQuery();
- rs.next();
- //System.out.println(count);
- count=rs.getInt(1);
- }catch(SQLException e)
- {
- System.out.println("Error in keyExists access: " + e.getSQLState());
- System.out.println("/nError Code: " + e.getErrorCode());
- System.out.println("/nMessage: " + e.getMessage());
- System.exit( 1 );
- }
- catch(Exception e)
- {
- System.out.println("unknown Error in keyExists");
- System.out.println("/nMessage: " + e.getMessage());
- System.exit( 1 );
- }
- finally
- {
- if (con != null)
- System.out.println("closing Uses connection \n");
- rs.close();
- ps.close();
- }
- if (count==1) {
- return true;
- } else {
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement