Search in sources :

Example 51 with ResultSet

use of java.sql.ResultSet in project Openfire by igniterealtime.

the class Config method createCallRecord.

public static void createCallRecord(String username, String addressFrom, String addressTo, long datetime, int duration, String calltype) {
    if (sipPlugin) {
        Log.info("createCallRecord " + username + " " + addressFrom + " " + addressTo + " " + datetime);
        String sql = "INSERT INTO ofSipPhoneLog (username, addressFrom, addressTo, datetime, duration, calltype) values  (?, ?, ?, ?, ?, ?)";
        Connection con = null;
        PreparedStatement psmt = null;
        ResultSet rs = null;
        try {
            con = DbConnectionManager.getConnection();
            psmt = con.prepareStatement(sql);
            psmt.setString(1, username);
            psmt.setString(2, addressFrom);
            psmt.setString(3, addressTo);
            psmt.setLong(4, datetime);
            psmt.setInt(5, duration);
            psmt.setString(6, calltype);
            psmt.executeUpdate();
        } catch (SQLException e) {
            Log.error(e.getMessage(), e);
        } finally {
            DbConnectionManager.closeConnection(rs, psmt, con);
        }
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 52 with ResultSet

use of java.sql.ResultSet in project Openfire by igniterealtime.

the class Config method processRegistrations.

private void processRegistrations() {
    String sql = "SELECT username, sipusername, sipauthuser, sipdisplayname, sippassword, sipserver, enabled, status, stunserver, stunport, usestun, voicemail, outboundproxy, promptCredentials FROM ofSipUser ORDER BY USERNAME";
    Connection con = null;
    PreparedStatement pstmt = null;
    try {
        con = DbConnectionManager.getConnection();
        pstmt = DbConnectionManager.createScrollablePreparedStatement(con, sql);
        ResultSet rs = pstmt.executeQuery();
        DbConnectionManager.scrollResultSet(rs, 0);
        while (rs.next()) {
            ProxyCredentials credentials = read(rs);
            try {
                InetAddress inetAddress = InetAddress.getByName(credentials.getHost());
                registrars.add(credentials.getHost());
                registrations.add(credentials);
                Log.info(String.format("VoiceBridge adding SIP registration: %s with user %s host %s", credentials.getXmppUserName(), credentials.getUserName(), credentials.getHost()));
            } catch (Exception e) {
                Log.info(String.format("processRegistrations Bad Address  %s ", credentials.getHost()));
            }
        }
        rs.close();
        pstmt.close();
        con.close();
    } catch (SQLException e) {
        Log.info("processRegistrations " + e);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) InetAddress(java.net.InetAddress) SQLException(java.sql.SQLException)

Example 53 with ResultSet

use of java.sql.ResultSet in project Openfire by igniterealtime.

the class SipAccountDAO method getAccountByUser.

public static SipAccount getAccountByUser(String username) {
    String sql = "SELECT username, sipusername, sipauthuser, sipdisplayname, sippassword, sipserver, enabled, " + "status, stunserver, stunport, usestun, voicemail, outboundproxy, promptCredentials FROM ofSipUser " + "WHERE username = ? ";
    SipAccount sipAccount = null;
    Connection con = null;
    PreparedStatement psmt = null;
    ResultSet rs = null;
    try {
        con = DbConnectionManager.getConnection();
        psmt = con.prepareStatement(sql);
        psmt.setString(1, username);
        rs = psmt.executeQuery();
        if (rs.next()) {
            sipAccount = read(rs);
        }
    } catch (SQLException e) {
        Log.error(e.getMessage(), e);
    } finally {
        DbConnectionManager.closeConnection(rs, psmt, con);
    }
    return sipAccount;
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 54 with ResultSet

use of java.sql.ResultSet in project Openfire by igniterealtime.

the class SipAccountDAO method getUserCount.

public static int getUserCount() {
    int count = 0;
    String sql = "SELECT count(*) FROM ofSipUser";
    Connection con = null;
    PreparedStatement pstmt = null;
    try {
        con = DbConnectionManager.getConnection();
        pstmt = con.prepareStatement(sql);
        ResultSet rs = pstmt.executeQuery();
        if (rs.next()) {
            count = rs.getInt(1);
        }
        rs.close();
    } catch (SQLException e) {
        Log.error(e.getMessage(), e);
    } finally {
        try {
            if (pstmt != null) {
                pstmt.close();
            }
        } catch (Exception e) {
            Log.error(e.getMessage(), e);
        }
        try {
            if (con != null) {
                con.close();
            }
        } catch (Exception e) {
            Log.error(e.getMessage(), e);
        }
    }
    return count;
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) SQLException(java.sql.SQLException)

Example 55 with ResultSet

use of java.sql.ResultSet in project head by mifos.

the class AccountingDaoImpl method getTenTxnDate.

@Override
public final List<LocalDate> getTenTxnDate(LocalDate startDate, LocalDate endDate, Integer offset) {
    Object[] parameter = new Object[] { startDate.toString(), endDate.toString(), offset };
    List<LocalDate> tenTrxn = jdbcTemplate.query(getTenTrxDataQuery(), parameter, new ParameterizedRowMapper<LocalDate>() {

        @Override
        public LocalDate mapRow(ResultSet rs, int rowNum) throws SQLException {
            return new LocalDate(rs.getDate(1).getTime());
        }
    });
    return tenTrxn;
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) LocalDate(org.joda.time.LocalDate)

Aggregations

ResultSet (java.sql.ResultSet)15888 PreparedStatement (java.sql.PreparedStatement)9451 SQLException (java.sql.SQLException)6466 Connection (java.sql.Connection)6445 Statement (java.sql.Statement)4619 Test (org.junit.Test)3647 ArrayList (java.util.ArrayList)2376 Properties (java.util.Properties)1233 HashMap (java.util.HashMap)639 ResultSetMetaData (java.sql.ResultSetMetaData)620 CallableStatement (java.sql.CallableStatement)580 DatabaseMetaData (java.sql.DatabaseMetaData)499 IOException (java.io.IOException)438 List (java.util.List)433 PhoenixConnection (org.apache.phoenix.jdbc.PhoenixConnection)414 Timestamp (java.sql.Timestamp)363 Map (java.util.Map)359 BigDecimal (java.math.BigDecimal)350 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)292 HashSet (java.util.HashSet)247