Search in sources :

Example 61 with PreparedStatement

use of java.sql.PreparedStatement in project syncany by syncany.

the class FileHistorySqlDao method getLastVersionByFileHistoryId.

private PartialFileHistory getLastVersionByFileHistoryId(String fileHistoryId) {
    try (PreparedStatement preparedStatement = getStatement("filehistory.select.master.getLastVersionByFileHistoryId.sql")) {
        preparedStatement.setString(1, fileHistoryId);
        preparedStatement.setString(2, fileHistoryId);
        try (ResultSet resultSet = preparedStatement.executeQuery()) {
            if (resultSet.next()) {
                FileVersion lastFileVersion = fileVersionDao.createFileVersionFromRow(resultSet);
                FileHistoryId fileHistoryIdData = FileHistoryId.parseFileId(resultSet.getString("filehistory_id"));
                PartialFileHistory fileHistory = new PartialFileHistory(fileHistoryIdData);
                fileHistory.addFileVersion(lastFileVersion);
                return fileHistory;
            } else {
                return null;
            }
        }
    } catch (SQLException e) {
        throw new RuntimeException(e);
    }
}
Also used : FileHistoryId(org.syncany.database.PartialFileHistory.FileHistoryId) SQLException(java.sql.SQLException) FileVersion(org.syncany.database.FileVersion) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) PartialFileHistory(org.syncany.database.PartialFileHistory)

Example 62 with PreparedStatement

use of java.sql.PreparedStatement in project syncany by syncany.

the class MultiChunkSqlDao method removeNonMuddyMultiChunks.

public void removeNonMuddyMultiChunks() throws SQLException {
    PreparedStatement preparedStatement = getStatement("multichunk_muddy.delete.muddy.removeNonMuddyMultiChunks.sql");
    preparedStatement.executeUpdate();
    preparedStatement.close();
}
Also used : PreparedStatement(java.sql.PreparedStatement)

Example 63 with PreparedStatement

use of java.sql.PreparedStatement in project KeyBox by skavanagh.

the class UserThemeDB method saveTheme.

/**
     * saves user theme
     * 
     * @param userId object
     */
public static void saveTheme(Long userId, UserSettings theme) {
    Connection con = null;
    try {
        con = DBUtils.getConn();
        PreparedStatement stmt = con.prepareStatement("delete from user_theme where user_id=?");
        stmt.setLong(1, userId);
        stmt.execute();
        DBUtils.closeStmt(stmt);
        if (org.apache.commons.lang.StringUtils.isNotEmpty(theme.getPlane()) || org.apache.commons.lang.StringUtils.isNotEmpty(theme.getTheme())) {
            stmt = con.prepareStatement("insert into user_theme(user_id, bg, fg, d1, d2, d3, d4, d5, d6, d7, d8, b1, b2, b3, b4, b5, b6, b7, b8) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
            stmt.setLong(1, userId);
            stmt.setString(2, theme.getBg());
            stmt.setString(3, theme.getFg());
            //if contains all 16 theme colors insert
            if (theme.getColors() != null && theme.getColors().length == 16) {
                for (int i = 0; i < 16; i++) {
                    stmt.setString(i + 4, theme.getColors()[i]);
                }
            //else set to null
            } else {
                for (int i = 0; i < 16; i++) {
                    stmt.setString(i + 4, null);
                }
            }
            stmt.execute();
            DBUtils.closeStmt(stmt);
        }
    } catch (Exception e) {
        log.error(e.toString(), e);
    } finally {
        DBUtils.closeConn(con);
    }
}
Also used : Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement)

Example 64 with PreparedStatement

use of java.sql.PreparedStatement in project nutz by nutzam.

the class AbstractJdbcExpert method getIndexNames.

@Override
public List<String> getIndexNames(Entity<?> en, Connection conn) throws SQLException {
    List<String> names = new ArrayList<String>();
    String showIndexs = "show index from " + en.getTableName();
    PreparedStatement ppstat = conn.prepareStatement(showIndexs);
    ResultSet rest = ppstat.executeQuery();
    while (rest.next()) {
        String index = rest.getString(3);
        names.add(index);
    }
    return names;
}
Also used : ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 65 with PreparedStatement

use of java.sql.PreparedStatement in project nutz by nutzam.

the class DaoPerformanceTest method jdbc.

public static void jdbc(DataSource ds, List<Pojo> list) throws Throwable {
    Stopwatch sw = Stopwatch.begin();
    Connection conn = ds.getConnection();
    PreparedStatement ps = conn.prepareStatement("insert into tb_pojo(name) values(?)");
    for (Pojo pojo : list) {
        ps.setString(1, pojo.getName());
        ps.addBatch();
    }
    ps.executeBatch();
    conn.commit();
    conn.close();
    sw.stop();
    System.out.printf("JDBC 批量插入%d条,耗时%dms\n", num, sw.getDuration());
}
Also used : Stopwatch(org.nutz.lang.Stopwatch) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement)

Aggregations

PreparedStatement (java.sql.PreparedStatement)6623 ResultSet (java.sql.ResultSet)4065 SQLException (java.sql.SQLException)3538 Connection (java.sql.Connection)2806 Test (org.junit.Test)1103 ArrayList (java.util.ArrayList)963 Properties (java.util.Properties)743 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)345 Statement (java.sql.Statement)273 Timestamp (java.sql.Timestamp)260 DatabaseException (net.jforum.exceptions.DatabaseException)254 PhoenixConnection (org.apache.phoenix.jdbc.PhoenixConnection)251 HashMap (java.util.HashMap)209 BigDecimal (java.math.BigDecimal)207 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)174 DbConnection (com.zimbra.cs.db.DbPool.DbConnection)165 List (java.util.List)150 IOException (java.io.IOException)145 Date (java.util.Date)133 Date (java.sql.Date)126