Example usage for java.sql CallableStatement setLong

List of usage examples for java.sql CallableStatement setLong

Introduction

In this page you can find the example usage for java.sql CallableStatement setLong.

Prototype

void setLong(String parameterName, long x) throws SQLException;

Source Link

Document

Sets the designated parameter to the given Java long value.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    String WRITE_OBJECT_SQL = "BEGIN " + "  INSERT INTO java_objects(object_id, object_name, object_value) "
            + "  VALUES (?, ?, empty_blob()) " + "  RETURN object_value INTO ?; " + "END;";
    String READ_OBJECT_SQL = "SELECT object_value FROM java_objects WHERE object_id = ?";

    Connection conn = getOracleConnection();
    conn.setAutoCommit(false);//from w  w w .  j a v  a2  s  . c o  m
    List<Object> list = new ArrayList<Object>();
    list.add("This is a short string.");
    list.add(new Integer(1234));
    list.add(new java.util.Date());

    // write object to Oracle
    long id = 0001;
    String className = list.getClass().getName();
    CallableStatement cstmt = conn.prepareCall(WRITE_OBJECT_SQL);

    cstmt.setLong(1, id);
    cstmt.setString(2, className);

    cstmt.registerOutParameter(3, java.sql.Types.BLOB);

    cstmt.executeUpdate();
    BLOB blob = (BLOB) cstmt.getBlob(3);
    OutputStream os = blob.getBinaryOutputStream();
    ObjectOutputStream oop = new ObjectOutputStream(os);
    oop.writeObject(list);
    oop.flush();
    oop.close();
    os.close();

    // Read object from oracle
    PreparedStatement pstmt = conn.prepareStatement(READ_OBJECT_SQL);
    pstmt.setLong(1, id);
    ResultSet rs = pstmt.executeQuery();
    rs.next();
    InputStream is = rs.getBlob(1).getBinaryStream();
    ObjectInputStream oip = new ObjectInputStream(is);
    Object object = oip.readObject();
    className = object.getClass().getName();
    oip.close();
    is.close();
    rs.close();
    pstmt.close();
    conn.commit();

    // de-serialize list a java object from a given objectID
    List listFromDatabase = (List) object;
    System.out.println("[After De-Serialization] list=" + listFromDatabase);
    conn.close();
}

From source file:com.mobilewallet.common.dao.FeedBackDAO.java

public void feedBack(long userId, String feedType, String feedText, String ip, String email) {
    Connection connection = null;
    CallableStatement cstmt = null;

    try {//from  ww  w.  j av  a  2 s.c om
        connection = dataSource.getConnection();
        cstmt = connection.prepareCall("{call FEEDBACK_PROC(?,?,?,?,?)}");
        cstmt.setLong(1, userId);
        cstmt.setString(2, feedType);
        cstmt.setString(3, feedText);
        cstmt.setString(4, email);
        cstmt.setString(5, ip);
        cstmt.execute();

    } catch (Exception ex) {
        ex.printStackTrace();
    } finally {
        try {
            if (cstmt != null) {
                cstmt.close();
            }
        } catch (Exception ex) {

        }
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (Exception ex) {

        }
    }
}

From source file:com.mobilewallet.users.dao.PushNotificationsDAO.java

public int updateNotification(long userId, String status, String type) {
    int updated = 0;
    Connection connection = null;
    CallableStatement cstmt = null;
    try {/*from   w  w  w .  j  a  v a2s  . c  o m*/
        connection = dataSource.getConnection();
        cstmt = connection.prepareCall("{call UPDATE_PUSH_NOTIFICATIONS(?,?,?,?)}");
        cstmt.setLong(1, userId);
        cstmt.setString(2, status);
        cstmt.setString(3, type);
        cstmt.registerOutParameter(4, java.sql.Types.INTEGER);
        cstmt.execute();

        updated = cstmt.getInt(4);
    } catch (Exception ex) {

    } finally {
        try {
            if (cstmt != null) {
                cstmt.close();
            }
        } catch (Exception ex) {

        }
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (Exception ex) {

        }
    }
    return updated;
}

From source file:com.mobilewallet.users.dao.NotificationsDAO.java

public int updateNotification(long userId, String status, String type) {
    int updated = 0;
    Connection connection = null;
    CallableStatement cstmt = null;
    try {//w ww  .jav a2  s .co  m
        connection = dataSource.getConnection();
        cstmt = connection.prepareCall("{call wp_update_push_notification(?,?,?,?)}");
        cstmt.setLong(1, userId);
        cstmt.setString(2, status);
        cstmt.setString(3, type);
        cstmt.registerOutParameter(4, java.sql.Types.INTEGER);
        cstmt.execute();

        updated = cstmt.getInt(4);
    } catch (Exception ex) {

    } finally {
        try {
            if (cstmt != null) {
                cstmt.close();
            }
        } catch (Exception ex) {

        }
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (Exception ex) {

        }
    }
    return updated;
}

From source file:com.mobilewallet.common.dao.ReferralIncentiveDAO.java

public String showInvitationStrig(long userId) {
    Connection connection = null;
    CallableStatement cstmt = null;
    String show = null;//from w  w  w  . jav  a2 s  .c  o  m

    try {
        connection = dataSource.getConnection();
        cstmt = connection.prepareCall("{call wp_show_invitation(?,?)}");
        cstmt.setLong(1, userId);
        cstmt.registerOutParameter(2, java.sql.Types.VARCHAR);

        cstmt.execute();

        show = cstmt.getString(2);

    } catch (Exception ex) {
        ex.printStackTrace();
    } finally {
        try {
            if (cstmt != null) {
                cstmt.close();
            }
        } catch (Exception ex) {

        }
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (Exception ex) {

        }
    }

    return show;
}

From source file:com.mobilewallet.common.dao.ReferralIncentiveDAO.java

public Object[] addReferralIncetive(long userId, String refCode, String imei, String ip) {
    int added = 0;
    Connection connection = null;
    CallableStatement cstmt = null;
    String gcmId = null;//www.  jav a  2s  .c om
    Object[] obj = null;
    try {
        connection = dataSource.getConnection();
        cstmt = connection.prepareCall("{call ADD_REFERRAL_CREDIT(?,?,?,?,?,?,?)}");
        cstmt.setLong(1, userId);
        cstmt.setString(2, refCode);
        cstmt.setString(3, imei);
        cstmt.setString(4, ip);
        cstmt.registerOutParameter(5, java.sql.Types.INTEGER);
        cstmt.registerOutParameter(6, java.sql.Types.VARCHAR);
        cstmt.registerOutParameter(7, java.sql.Types.VARCHAR);

        cstmt.execute();

        added = cstmt.getInt(5);
        gcmId = cstmt.getString(6);
        obj = new Object[3];
        obj[0] = added;
        obj[1] = gcmId;
        obj[2] = cstmt.getString(7);
    } catch (Exception ex) {
        ex.printStackTrace();
        log.error("Error in add referral incentive dao : " + ex.getMessage() + ", USER ID " + userId
                + ", refCode : " + refCode + ", imei : " + imei + ", IP : " + ip);
    } finally {
        try {
            if (cstmt != null) {
                cstmt.close();
            }
        } catch (Exception ex) {

        }
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (Exception ex) {

        }
    }

    return obj;
}

From source file:com.mobilewallet.users.dao.UserQuestionsDAO.java

public int submitQuestion(long userId, String question, String answerA, String answerB, String answerC,
        String answerD, String answer) {
    Connection connection = null;
    CallableStatement pstmt = null;
    ResultSet rs = null;/*  w  w w.  j  a  v a 2  s.  c  o  m*/
    int submitted = 0;
    try {
        connection = dataSource.getConnection();
        pstmt = connection.prepareCall("{call submit_question(?,?,?,?,?,?,?,?)}");
        pstmt.setLong(1, userId);
        pstmt.setString(2, question);
        pstmt.setString(3, answerA);
        pstmt.setString(4, answerB);
        pstmt.setString(5, answerC);
        pstmt.setString(6, answerD);
        pstmt.setString(7, answer);
        pstmt.registerOutParameter(8, java.sql.Types.INTEGER);
        pstmt.execute();
        submitted = pstmt.getInt(8);
    } catch (Exception ex) {
        ex.printStackTrace();
    } finally {

        try {
            if (rs != null) {
                rs.close();
            }
        } catch (Exception ex) {

        }
        try {
            if (pstmt != null) {
                pstmt.close();
            }
        } catch (Exception ex) {

        }
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (Exception ex) {

        }
    }
    return submitted;
}

From source file:com.mobilewallet.credits.dao.CreditsDAO.java

public int updateCredits(long userId, String isCorrect, int position) {
    int updated = 0;
    Connection connection = null;
    CallableStatement cstmt = null;
    try {/*from  ww  w . j a  v a 2s .  co m*/
        connection = dataSource.getConnection();
        cstmt = connection.prepareCall("{call update_credits_proc(?,?,?,?)}");
        cstmt.setLong(1, userId);
        cstmt.setString(2, isCorrect);
        cstmt.setInt(3, position);
        cstmt.registerOutParameter(4, java.sql.Types.INTEGER);
        cstmt.execute();

        updated = cstmt.getInt(4);
    } catch (Exception ex) {
        ex.printStackTrace();
    } finally {

        try {
            if (cstmt != null) {
                cstmt.close();
            }
        } catch (Exception ex) {

        }
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (Exception ex) {

        }
    }
    return updated;
}

From source file:com.mobilewallet.admin.dao.QuestionDAO.java

public int approveQuestion(long userId, long q_id, String is_admin_approved) {
    Connection connection = null;
    CallableStatement pstmt = null;
    ResultSet rs = null;/*from   w  w w .j ava 2s .c o m*/
    int approved = 0;
    try {
        connection = dataSource.getConnection();
        pstmt = connection.prepareCall("{call approve_question(?,?,?,?)}");
        pstmt.setLong(1, userId);
        pstmt.setLong(2, q_id);
        pstmt.setString(3, is_admin_approved);

        pstmt.registerOutParameter(4, java.sql.Types.INTEGER);
        pstmt.execute();
        approved = pstmt.getInt(4);
    } catch (Exception ex) {
        ex.printStackTrace();
    } finally {

        try {
            if (rs != null) {
                rs.close();
            }
        } catch (Exception ex) {

        }
        try {
            if (pstmt != null) {
                pstmt.close();
            }
        } catch (Exception ex) {

        }
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (Exception ex) {

        }
    }
    return approved;
}

From source file:com.mobilewallet.users.dao.UserDAO.java

public int updateProfile(long userId, String mCode, String mobileNumber, String dob, String gender,
        String occupation, String income) {
    Connection connection = null;
    CallableStatement pstmt = null;
    ResultSet rs = null;/*w ww. ja va2s  .  c  o  m*/
    int updated = 0;
    try {
        connection = dataSource.getConnection();
        pstmt = connection.prepareCall("{call UPDATE_PROFILE(?,?,?,?,?,?,?,?)}");
        pstmt.setLong(1, userId);
        pstmt.setString(2, mCode);
        pstmt.setString(3, mobileNumber);
        pstmt.setString(4, dob);
        pstmt.setString(5, gender);
        pstmt.setString(6, occupation);
        pstmt.setString(7, income);
        pstmt.registerOutParameter(8, java.sql.Types.INTEGER);
        pstmt.execute();
        updated = pstmt.getInt(8);
    } catch (Exception ex) {
        ex.printStackTrace();
    } finally {

        try {
            if (rs != null) {
                rs.close();
            }
        } catch (Exception ex) {

        }
        try {
            if (pstmt != null) {
                pstmt.close();
            }
        } catch (Exception ex) {

        }
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (Exception ex) {

        }
    }
    return updated;
}