List of usage examples for java.sql PreparedStatement setString
void setString(int parameterIndex, String x) throws SQLException;
String
value. From source file:com.trackplus.ddl.DataWriter.java
private static void insertBlobData(Connection con, String line) throws DDLException { String sql = "INSERT INTO TBLOB(OBJECTID, BLOBVALUE, TPUUID) VALUES(?,?,?)"; StringTokenizer st = new StringTokenizer(line, ","); Integer objectID = Integer.valueOf(st.nextToken()); String base64Str = st.nextToken(); byte[] bytes = Base64.decodeBase64(base64Str); String tpuid = null;// w w w . j a va 2s.c o m if (st.hasMoreTokens()) { tpuid = st.nextToken(); } try { PreparedStatement preparedStatement = con.prepareStatement(sql); preparedStatement.setInt(1, objectID); preparedStatement.setBinaryStream(2, new ByteArrayInputStream(bytes), bytes.length); preparedStatement.setString(3, tpuid); preparedStatement.executeUpdate(); } catch (SQLException e) { throw new DDLException(e.getMessage(), e); } }
From source file:at.becast.youploader.database.SQLite.java
public static void updatePlaylist(Item item) throws SQLException, IOException { PreparedStatement prest = null; String sql = "UPDATE `playlists` SET `name`=?,`image`=? WHERE `playlistid`=?"; prest = c.prepareStatement(sql);/*from www. ja v a 2s .co m*/ prest.setString(1, item.snippet.title); URL url = new URL(item.snippet.thumbnails.default__.url); InputStream is = null; is = url.openStream(); byte[] imageBytes = IOUtils.toByteArray(is); prest.setBytes(2, imageBytes); prest.setString(3, item.id); prest.execute(); prest.close(); }
From source file:module.entities.NameFinder.DB.java
public static void saveClusterAnnotatedDocuments(TreeMap<Integer, String> docs) throws SQLException { String insertSQL = "INSERT INTO assignments_herc (annotator_id,text_id,json_out) VALUES (-1,?,?)"; PreparedStatement stmt = connection.prepareStatement(insertSQL); for (Map.Entry<Integer, String> pair : docs.entrySet()) { stmt.setInt(1, pair.getKey());/*from w w w . j a v a2 s . c om*/ stmt.setString(2, pair.getValue()); stmt.addBatch(); } stmt.executeBatch(); }
From source file:com.act.lcms.db.model.Plate.java
protected static void bindInsertOrUpdateParameters(PreparedStatement stmt, String name, String description, String barcode, String location, String plateType, String solvent, Integer temperature, CONTENT_TYPE contentType) throws SQLException { stmt.setString(DB_FIELD.NAME.getInsertUpdateOffset(), trimAndComplain(name)); if (description != null) { stmt.setString(DB_FIELD.DESCRIPTION.getInsertUpdateOffset(), trimAndComplain(description)); } else {// ww w .ja va 2s. co m stmt.setNull(DB_FIELD.DESCRIPTION.getInsertUpdateOffset(), Types.VARCHAR); } if (barcode != null) { stmt.setString(DB_FIELD.BARCODE.getInsertUpdateOffset(), trimAndComplain(barcode)); } else { stmt.setNull(DB_FIELD.BARCODE.getInsertUpdateOffset(), Types.VARCHAR); } stmt.setString(DB_FIELD.LOCATION.getInsertUpdateOffset(), trimAndComplain(location)); stmt.setString(DB_FIELD.PLATE_TYPE.getInsertUpdateOffset(), trimAndComplain(plateType)); if (solvent != null) { stmt.setString(DB_FIELD.SOLVENT.getInsertUpdateOffset(), trimAndComplain(solvent)); } else { stmt.setNull(DB_FIELD.SOLVENT.getInsertUpdateOffset(), Types.VARCHAR); } if (temperature == null) { stmt.setNull(DB_FIELD.TEMPERATURE.getInsertUpdateOffset(), Types.INTEGER); } else { stmt.setInt(DB_FIELD.TEMPERATURE.getInsertUpdateOffset(), temperature); } stmt.setString(DB_FIELD.CONTENT_TYPE.getInsertUpdateOffset(), contentType.name()); }
From source file:com.keybox.manage.db.UserDB.java
/** * inserts new user/*from ww w .j a va2s . c om*/ * * @param con DB connection * @param user user object */ public static Long insertUser(Connection con, User user) { Long userId = null; try { PreparedStatement stmt = con.prepareStatement( "insert into users (first_nm, last_nm, email, username, auth_type, user_type, password, salt) values (?,?,?,?,?,?,?,?)", Statement.RETURN_GENERATED_KEYS); stmt.setString(1, user.getFirstNm()); stmt.setString(2, user.getLastNm()); stmt.setString(3, user.getEmail()); stmt.setString(4, user.getUsername()); stmt.setString(5, user.getAuthType()); stmt.setString(6, user.getUserType()); if (StringUtils.isNotEmpty(user.getPassword())) { String salt = EncryptionUtil.generateSalt(); stmt.setString(7, EncryptionUtil.hash(user.getPassword() + salt)); stmt.setString(8, salt); } else { stmt.setString(7, null); stmt.setString(8, null); } stmt.execute(); ResultSet rs = stmt.getGeneratedKeys(); if (rs != null && rs.next()) { userId = rs.getLong(1); } DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } return userId; }
From source file:com.sql.CaseParty.java
public static List<CasePartyModel> getCasePartyList(String caseYear, String caseType, String caseMonth, String caseNumber) {/*from ww w. j a v a 2s . c o m*/ List<CasePartyModel> list = new ArrayList(); Connection conn = null; PreparedStatement ps = null; ResultSet rs = null; try { conn = DBConnection.connectToDB(); String sql = "SELECT" + " caseRelation," + " LastName," + " FirstName," + " MiddleInitial," + " jobTitle," + " companyName," + " Address1," + " Address2," + " City," + " stateCode," + " zipCode," + " phone1 FROM " + " caseParty" + " WHERE" + " caseyear = ?" + " AND casetype = ?" + " AND casemonth = ?" + " AND caseNumber = ?"; ps = conn.prepareStatement(sql); ps.setString(1, caseYear); ps.setString(2, caseType); ps.setString(3, caseMonth); ps.setString(4, caseNumber); rs = ps.executeQuery(); while (rs.next()) { CasePartyModel item = new CasePartyModel(); item.setCaseRelation(rs.getString("caseRelation") == null ? "" : rs.getString("caseRelation")); item.setLastName(rs.getString("LastName") == null ? "" : rs.getString("LastName")); item.setFirstName(rs.getString("FirstName") == null ? "" : rs.getString("FirstName")); item.setMiddleInitial(rs.getString("MiddleInitial") == null ? "" : rs.getString("MiddleInitial")); item.setJobTitle(rs.getString("jobTitle") == null ? "" : rs.getString("jobTitle")); item.setCompanyName(rs.getString("companyName") == null ? "" : rs.getString("companyName")); item.setAddress1(rs.getString("Address1") == null ? "" : rs.getString("Address1")); item.setAddress2(rs.getString("Address2") == null ? "" : rs.getString("Address2")); item.setCity(rs.getString("City") == null ? "" : rs.getString("City")); item.setStateCode(rs.getString("stateCode") == null ? "" : rs.getString("stateCode")); item.setZipcode(rs.getString("zipCode") == null ? "" : rs.getString("zipCode")); item.setPhone1(rs.getString("phone1") == null ? "" : rs.getString("phone1")); list.add(item); } } catch (SQLException ex) { if (ex.getCause() instanceof SQLServerException) { getCasePartyList(caseYear, caseType, caseMonth, caseNumber); } } finally { DbUtils.closeQuietly(conn); DbUtils.closeQuietly(ps); DbUtils.closeQuietly(rs); } return list; }
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 ww w . ja va 2 s . co m 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:at.becast.youploader.database.SQLite.java
public static boolean failUpload(int upload_id) { PreparedStatement prest = null; String sql = "UPDATE `uploads` SET `status`=?,`uploaded`=? WHERE `id`=?"; try {/*from ww w. jav a2 s .c o m*/ prest = c.prepareStatement(sql); prest.setString(1, UploadManager.Status.FAILED.toString()); prest.setInt(3, upload_id); boolean res = prest.execute(); prest.close(); return res; } catch (SQLException e) { LOG.error("Error marking upload as failed", e); return false; } }
From source file:at.becast.youploader.database.SQLite.java
public static Boolean prepareUpload(int id, String Url, String yt_id) { PreparedStatement prest = null; String sql = "UPDATE `uploads` SET `status`=?,`url`=?,`yt_id`=? WHERE `id`=?"; try {//from w ww . j av a2 s.c om prest = c.prepareStatement(sql); prest.setString(1, UploadManager.Status.PREPARED.toString()); prest.setString(2, Url); prest.setString(3, yt_id); prest.setInt(4, id); boolean res = prest.execute(); prest.close(); return res; } catch (SQLException e) { LOG.error("Error preparing upload", e); return false; } }
From source file:database.HashTablesTools.java
private static void insertIntoFailureTable(Connection connexion, String tableFailureName, String hash, String fourLetterCode) {//from ww w. j a v a 2s .co m try { String insertTableSQL = "INSERT INTO " + tableFailureName + " " + "(pdbfilehash, fourLettercode) VALUES" + "(?,?)"; PreparedStatement preparedStatement = connexion.prepareStatement(insertTableSQL); preparedStatement.setString(1, hash); preparedStatement.setString(2, String.valueOf(fourLetterCode)); int ok = preparedStatement.executeUpdate(); preparedStatement.close(); System.out.println(ok + " raw created in failure table" + String.valueOf(fourLetterCode)); } catch (SQLException e1) { System.out.println("Failed to enter entry in " + tableFailureName + " table "); } }