List of usage examples for java.sql PreparedStatement setLong
void setLong(int parameterIndex, long x) throws SQLException;
long
value. From source file:at.becast.youploader.database.SQLite.java
public static Boolean startUpload(int id, long progress) { PreparedStatement prest = null; String sql = "UPDATE `uploads` SET `status`=?,`uploaded`=? WHERE `id`=?"; try {/*from w w w . java 2s. c om*/ prest = c.prepareStatement(sql); prest.setString(1, UploadManager.Status.UPLOADING.toString()); prest.setLong(2, progress); prest.setInt(3, id); boolean res = prest.execute(); prest.close(); return res; } catch (SQLException e) { LOG.error("Error starting upload", e); return false; } }
From source file:com.keybox.manage.db.PublicKeyDB.java
/** * deletes public key/*w w w . j av a2s . c o m*/ * * @param publicKeyId key id * @param userId user id */ public static void deletePublicKey(Long publicKeyId, Long userId) { Connection con = null; try { con = DBUtils.getConn(); PreparedStatement stmt = con .prepareStatement("delete from public_keys where id=? and user_id=? and enabled=true"); stmt.setLong(1, publicKeyId); stmt.setLong(2, userId); stmt.execute(); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } DBUtils.closeConn(con); }
From source file:at.becast.youploader.database.SQLite.java
public static Boolean updateUpload(int account, File file, Video data, String enddir, VideoMetadata metadata, int id) throws SQLException, IOException { PreparedStatement prest = null; String sql = "UPDATE `uploads` SET `account`=?, `file`=?, `lenght`=?, `enddir`=? WHERE `id`=?"; prest = c.prepareStatement(sql);/*w ww . j ava 2s . c om*/ prest.setInt(1, account); prest.setString(2, file.getAbsolutePath()); prest.setLong(3, file.length()); prest.setString(4, enddir); prest.setInt(5, id); boolean res = prest.execute(); prest.close(); boolean upd = updateUploadData(data, metadata, id); return res && upd; }
From source file:com.tethrnet.manage.db.PublicKeyDB.java
/** * select all unique public keys for user * * @param userId user id/*from w ww . j av a 2 s . c o m*/ * @return public key list for user */ public static List<PublicKey> getUniquePublicKeysForUser(Long userId) { Connection con = null; Map<String, PublicKey> keyMap = new LinkedHashMap(); try { con = DBUtils.getConn(); PreparedStatement stmt = con.prepareStatement( "select * from public_keys where user_id=? and enabled=true order by key_nm asc"); stmt.setLong(1, userId); ResultSet rs = stmt.executeQuery(); while (rs.next()) { PublicKey publicKey = new PublicKey(); publicKey.setId(rs.getLong("id")); publicKey.setKeyNm(rs.getString("key_nm")); publicKey.setPublicKey(rs.getString("public_key")); publicKey.setProfile(ProfileDB.getProfile(con, rs.getLong("profile_id"))); publicKey.setType(SSHUtil.getKeyType(publicKey.getPublicKey())); publicKey.setFingerprint(SSHUtil.getFingerprint(publicKey.getPublicKey())); publicKey.setCreateDt(rs.getTimestamp("create_dt")); keyMap.put(publicKey.getKeyNm() + " (" + publicKey.getFingerprint() + ")", publicKey); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } DBUtils.closeConn(con); return new ArrayList(keyMap.values()); }
From source file:com.keybox.manage.db.PublicKeyDB.java
/** * select all unique public keys for user * * @param userId user id//from w ww.ja v a 2 s. co m * @return public key list for user */ public static List<PublicKey> getUniquePublicKeysForUser(Long userId) { Connection con = null; Map<String, PublicKey> keyMap = new LinkedHashMap(); try { con = DBUtils.getConn(); PreparedStatement stmt = con.prepareStatement( "select * from public_keys where user_id=? and enabled=true order by key_nm asc"); stmt.setLong(1, userId); ResultSet rs = stmt.executeQuery(); while (rs.next()) { PublicKey publicKey = new PublicKey(); publicKey.setId(rs.getLong("id")); publicKey.setKeyNm(rs.getString(KEY_NM)); publicKey.setPublicKey(rs.getString(PUBLIC_KEY)); publicKey.setProfile(ProfileDB.getProfile(con, rs.getLong(PROFILE_ID))); publicKey.setType(SSHUtil.getKeyType(publicKey.getPublicKey())); publicKey.setFingerprint(SSHUtil.getFingerprint(publicKey.getPublicKey())); publicKey.setCreateDt(rs.getTimestamp(CREATE_DT)); keyMap.put(publicKey.getKeyNm() + " (" + publicKey.getFingerprint() + ")", publicKey); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } DBUtils.closeConn(con); return new ArrayList(keyMap.values()); }
From source file:DeliverWork.java
private static String saveIntoWeed(RemoteFile remoteFile, String projectId) throws SQLException, UnsupportedEncodingException { String url = "http://59.215.226.174/WebDiskServerDemo/doc?doc_id=" + URLEncoder.encode(remoteFile.getFileId(), "utf-8"); CloseableHttpClient httpClient = null; CloseableHttpResponse response = null; String res = ""; try {/*from w w w.j a v a2s . c o m*/ httpClient = HttpClients.createSystem(); // http(get?) HttpGet httpget = new HttpGet(url); response = httpClient.execute(httpget); HttpEntity result = response.getEntity(); String fileName = remoteFile.getFileName(); FileHandleStatus fileHandleStatus = getFileTemplate().saveFileByStream(fileName, new ByteArrayInputStream(EntityUtils.toByteArray(result))); System.out.println(fileHandleStatus); File file = new File(); if (result != null && result.getContentType() != null && result.getContentType().getValue() != null) { file.setContentType(result.getContentType().getValue()); } else { file.setContentType("application/error"); } file.setDataId(Integer.parseInt(projectId)); file.setName(fileName); if (fileName.contains(".bmp") || fileName.contains(".jpg") || fileName.contains(".jpeg") || fileName.contains(".png") || fileName.contains(".gif")) { file.setType(1); } else if (fileName.contains(".doc") || fileName.contains(".docx")) { file.setType(2); } else if (fileName.contains(".xlsx") || fileName.contains("xls")) { file.setType(3); } else if (fileName.contains(".pdf")) { file.setType(4); } else { file.setType(5); } String accessUrl = "/" + fileHandleStatus.getFileId().replaceAll(",", "/").concat("/").concat(fileName); file.setUrl(accessUrl); file.setSize(fileHandleStatus.getSize()); file.setPostTime(new java.util.Date()); file.setStatus(0); file.setEnumValue(findFileType(remoteFile.getFileType())); file.setResources(1); // JdbcFactory jdbcFactoryChanye=new JdbcFactory("jdbc:mysql://127.0.0.1:3306/fp_guimin?useUnicode=true&characterEncoding=UTF-8","root","111111","com.mysql.jdbc.Driver"); // Connection connection = jdbcFactoryChanye.getConnection(); DatabaseMetaData dmd = connection.getMetaData(); PreparedStatement ps = connection.prepareStatement(insertFile, new String[] { "ID" }); ps.setString(1, sdf.format(file.getPostTime())); ps.setInt(2, file.getType()); ps.setString(3, file.getEnumValue()); ps.setInt(4, file.getDataId()); ps.setString(5, file.getUrl()); ps.setString(6, file.getName()); ps.setString(7, file.getContentType()); ps.setLong(8, file.getSize()); ps.setInt(9, file.getStatus()); ps.setInt(10, file.getResources()); ps.executeUpdate(); if (dmd.supportsGetGeneratedKeys()) { ResultSet rs = ps.getGeneratedKeys(); while (rs.next()) { System.out.println(rs.getLong(1)); } } ps.close(); res = "success"; } catch (ClientProtocolException e) { e.printStackTrace(); res = e.getMessage(); } catch (IOException e) { e.printStackTrace(); res = e.getMessage(); } catch (Exception ex) { ex.printStackTrace(); } finally { if (httpClient != null) { try { httpClient.close(); } catch (IOException e) { e.printStackTrace(); } } if (response != null) { try { response.close(); } catch (IOException e) { e.printStackTrace(); } } } return res; }
From source file:com.keybox.manage.db.PublicKeyDB.java
/** * Deletes all SSH keys for users that are not assigned in a profile * * @param con DB connection//from w ww . java2 s .c o m * @param profileId profile id */ public static void deleteUnassignedKeysByProfile(Connection con, Long profileId) { try { PreparedStatement stmt = con.prepareStatement( "delete from public_keys where profile_id=? and user_id not in (select user_id from user_map where profile_id=?)"); stmt.setLong(1, profileId); stmt.setLong(2, profileId); stmt.execute(); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } }
From source file:com.keybox.manage.db.UserDB.java
/** * updates existing user/*from www.ja v a 2 s . c o m*/ * @param user user object */ public static void updateUserNoCredentials(User user) { Connection con = null; try { con = DBUtils.getConn(); PreparedStatement stmt = con.prepareStatement( "update users set first_nm=?, last_nm=?, email=?, username=?, user_type=? where id=?"); stmt.setString(1, user.getFirstNm()); stmt.setString(2, user.getLastNm()); stmt.setString(3, user.getEmail()); stmt.setString(4, user.getUsername()); stmt.setString(5, user.getUserType()); stmt.setLong(6, user.getId()); stmt.execute(); DBUtils.closeStmt(stmt); if (User.ADMINISTRATOR.equals(user.getUserType())) { PublicKeyDB.deleteUnassignedKeysByUser(con, user.getId()); } } catch (Exception e) { log.error(e.toString(), e); } DBUtils.closeConn(con); }
From source file:com.keybox.manage.db.PublicKeyDB.java
/** * Deletes all SSH keys for users that are not assigned in a profile * * @param con DB connection/*from w ww . ja v a 2 s. c o m*/ * @param userId user id */ public static void deleteUnassignedKeysByUser(Connection con, Long userId) { try { PreparedStatement stmt = con.prepareStatement( "delete from public_keys where (profile_id is null or profile_id not in (select profile_id from user_map where user_id=?)) and user_id=?"); stmt.setLong(1, userId); stmt.setLong(2, userId); stmt.execute(); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } }
From source file:com.tethrnet.manage.db.UserDB.java
/** * updates existing user//from ww w. j ava 2 s . c om * @param user user object */ public static void updateUserCredentials(User user) { Connection con = null; try { con = DBUtils.getConn(); String salt = EncryptionUtil.generateSalt(); PreparedStatement stmt = con.prepareStatement( "update users set email=?, username=?, user_type=?, password=?, salt=? where id=?"); stmt.setString(1, user.getEmail()); stmt.setString(2, user.getUsername()); stmt.setString(3, user.getUserType()); stmt.setString(4, EncryptionUtil.hash(user.getPassword() + salt)); stmt.setString(5, salt); stmt.setLong(6, user.getId()); stmt.execute(); DBUtils.closeStmt(stmt); if (User.ADMINISTRATOR.equals(user.getUserType())) { PublicKeyDB.deleteUnassignedKeysByUser(con, user.getId()); } } catch (Exception e) { log.error(e.toString(), e); } DBUtils.closeConn(con); }