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);
}
}
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();
}
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);
}
}
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;
}
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());
}
Aggregations