List of usage examples for java.sql PreparedStatement setLong
void setLong(int parameterIndex, long x) throws SQLException;
long
value. From source file:sample.contact.dao.impl.MenuDaoImpl.java
public int update(final Menu menu) { return getJdbcTemplate().update("update menus set menu_name = ?, menu_path = ? where id = ?", new PreparedStatementSetter() { public void setValues(PreparedStatement ps) throws SQLException { ps.setString(1, menu.getName()); ps.setString(2, menu.getPath()); ps.setLong(3, menu.getId()); }/*from www . j av a 2 s . co m*/ }); }
From source file:dao.ColStreamBlobAddQuery.java
/** * This method is used to add blobstreams for directory. * @param conn - the connection//ww w . ja v a 2 s .com * @param blob - the blob stream * @param blobType - the blob type (1 - photos, 2-music, 3-video 4 - * documents, 5 - archives) * @param mimeType - the mime type (image/jpeg, * application/octet-stream) * @param btitle - the title for this blob * @param bsize - the size of the blob * @param zoom - the zoom for the blob (used for displaying for * image/jpeg) * @param collabrumid - the collabrumid * @param loginId - the loginId * @param caption - caption * @throws Dao Exception - when an error or exception occurs while * inserting this blob in DB. * **/ public void run(Connection conn, byte[] blob, int blobtype, String mimetype, String btitle, long bsize, int zoom, String collabrumid, String loginid, String caption) throws BaseDaoException { // long dt = new java.util.Date().getTime(); byte[] capBytes = { ' ' }; if (!RegexStrUtil.isNull(caption)) { capBytes = caption.getBytes(); } long dt = System.currentTimeMillis(); PreparedStatement s = null; String stmt = "insert into collblob values(?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP(), ?, ?, ?, ?)"; try { s = conn.prepareStatement(stmt); s.setLong(1, 0); s.setLong(2, new Long(collabrumid)); s.setLong(3, new Long(loginid)); s.setInt(4, new Integer(blobtype)); s.setString(5, mimetype); s.setString(6, btitle); //s.setDate(7, new Date(dt)); s.setBytes(7, blob); s.setLong(8, bsize); s.setInt(9, new Integer(zoom)); s.setBytes(10, capBytes); s.executeUpdate(); } catch (Exception e) { throw new BaseDaoException("Error adding a blob to collabrum query stmt " + stmt, e); } }
From source file:com.ywang.alone.handler.task.AuthTask.java
/** * /* ww w . j a v a 2 s. c o m*/ * * @param param * * { * 'phoneNum':'ywang','password':'e10adc3949ba59abbe56e057f20f883 * e ','lng':'117.157954','lat':'31.873432', * 'deviceToken':'8a2597aa1d37d432a88a446d82b6561e','osVersion':' * 8 . 0 ' , 'systemType':'iOS','phoneModel':'iPhone 5s'} * * OR * * {'key':'2597aa1d37d432a','lng':'117.157954','lat':'31.873432', * 'deviceToken':'8a2597aa1d37d432a88a446d82b6561e','osVersion':' * 8 . 0 ' , 'systemType':'iOS','phoneModel':'iPhone 5s'} * * @return {"data":{"key":"e1e10c1ba704d1f10acda309138a2153","messagePwd": * "alone123456" * ,"messageUser":"15256551134324","online":"1","regTime" * :1415177594592,"userId":"23"},"errCode":0,"errDesc":"","ret":5} */ private static String login(String msg) { JSONObject jsonObject = AloneUtil.newRetJsonObject(); JSONObject user = JSON.parseObject(msg); DruidPooledConnection conn = null; PreparedStatement stmt = null; try { conn = DataSourceFactory.getInstance().getConn(); conn.setAutoCommit(false); String token = user.getString("key"); String userId = null; boolean needUpdateToken = false; if (StringUtils.isEmpty(token)) {// ??? needUpdateToken = true; String uuid = UUID.randomUUID().toString(); uuid = uuid.replaceAll("-", ""); token = MD5.getMD5String(uuid); stmt = conn.prepareStatement("SELECT * FROM userbase WHERE PHONE_NUM = ? AND PWD = ? "); stmt.setString(1, user.getString("phoneNum")); stmt.setString(2, user.getString("password")); } else {// token Jedis jedis = JedisUtil.getJedis(); Long tokenTtl = jedis.ttl("TOKEN:" + token); if (tokenTtl == -1) { jsonObject.put("ret", Constant.RET.NO_ACCESS_AUTH); jsonObject.put("errCode", Constant.ErrorCode.NO_ACCESS_AUTH); jsonObject.put("errDesc", Constant.ErrorDesc.NO_ACCESS_AUTH); } else { userId = jedis.get("TOKEN:" + token); LoggerUtil.logMsg("uid is " + userId + ""); } JedisUtil.returnJedis(jedis); if (StringUtils.isEmpty(userId + "")) { return jsonObject.toJSONString(); } stmt = conn.prepareStatement("SELECT * FROM userbase WHERE user_id = ?"); stmt.setString(1, userId + ""); } ResultSet rs = stmt.executeQuery(); if (rs.next()) { // UserInfo userInfo = new UserInfo(); userId = rs.getString("USER_ID"); userInfo.setRegTime(rs.getLong("REG_TIME")); userInfo.setUserId(userId + ""); userInfo.setAvatar(rs.getString("AVATAR")); userInfo.setNickName(rs.getString("NICKNAME")); userInfo.setAge(rs.getString("AGE")); userInfo.setHoroscope(rs.getString("HORO_SCOPE")); userInfo.setHeight(rs.getString("HEIGHT")); userInfo.setWeight(rs.getString("WEIGHT")); userInfo.setRoleName(rs.getString("ROLENAME")); userInfo.setAffection(rs.getString("AFFECTION")); userInfo.setPurpose(rs.getString("PURPOSE")); userInfo.setEthnicity(rs.getString("ETHNICITY")); userInfo.setOccupation(rs.getString("OCCUPATION")); userInfo.setLivecity(rs.getString("LIVECITY")); userInfo.setLocation(rs.getString("LOCATION")); userInfo.setTravelcity(rs.getString("TRAVELCITY")); userInfo.setMovie(rs.getString("MOVIE")); userInfo.setMusic(rs.getString("MUSIC")); userInfo.setBooks(rs.getString("BOOKS")); userInfo.setFood(rs.getString("FOOD")); userInfo.setOthers(rs.getString("OTHERS")); userInfo.setIntro(rs.getString("INTRO")); userInfo.setMessagePwd(rs.getString("MESSAGE_PWD")); userInfo.setMessageUser(rs.getString("MESSAGE_USER")); userInfo.setKey(token); userInfo.setOnline("1"); jsonObject.put("data", JSONObject.toJSON(userInfo)); // token ? PreparedStatement updatestmt = null; if (needUpdateToken) { updatestmt = conn.prepareStatement( "update userbase set PKEY = ?, LAST_LOGIN_TIME = ? , OS_VERSION=? , SYSTEM_TYPE=? , PHONE_MODEL=? , DEVICE_TOKEN=? , LNG=? , LAT=? , ONLINE='1' WHERE USER_ID=?"); updatestmt.setString(1, token); updatestmt.setLong(2, System.currentTimeMillis()); updatestmt.setString(3, user.getString("osVersion")); updatestmt.setString(4, user.getString("systemType")); updatestmt.setString(5, user.getString("phoneModel")); updatestmt.setString(6, user.getString("deviceToken")); updatestmt.setString(7, user.getString("lng")); updatestmt.setString(8, user.getString("lat")); updatestmt.setString(9, userInfo.getUserId()); } else { updatestmt = conn.prepareStatement( "update userbase set LAST_LOGIN_TIME = ? , LNG=? , LAT=? , OS_VERSION=? , SYSTEM_TYPE=? , PHONE_MODEL=? , DEVICE_TOKEN= ? , ONLINE='1' WHERE USER_ID=?"); updatestmt.setLong(1, System.currentTimeMillis()); updatestmt.setString(2, user.getString("lng")); updatestmt.setString(3, user.getString("lat")); updatestmt.setString(4, user.getString("osVersion")); updatestmt.setString(5, user.getString("systemType")); updatestmt.setString(6, user.getString("phoneModel")); updatestmt.setString(7, user.getString("deviceToken")); updatestmt.setString(8, userInfo.getUserId()); } int result = updatestmt.executeUpdate(); if (result != 1) { jsonObject.put("ret", Constant.RET.TOKEN_UPDATE_FAIL); jsonObject.put("errCode", Constant.ErrorCode.TOKEN_UPDATE_FAIL); jsonObject.put("errDesc", Constant.ErrorDesc.TOKEN_UPDATE_FAIL); } updatestmt.close(); } // else { jsonObject = regNewUser(msg); JSONObject data = jsonObject.getJSONObject("data"); userId = data.getString("userId"); token = data.getString("key"); LoggerUtil.logMsg("register succ userId is: " + userId + " token is " + token); } rs.close(); conn.commit(); conn.setAutoCommit(true); //redis Jedis jedis = JedisUtil.getJedis(); // jedis.setex("TOKEN:" + token, 86400 * 14, userId + ""); JedisUtil.returnJedis(jedis); } catch (SQLException e) { LoggerUtil.logServerErr(e); jsonObject.put("ret", Constant.RET.SYS_ERR); jsonObject.put("errCode", Constant.ErrorCode.SYS_ERR); jsonObject.put("errDesc", Constant.ErrorDesc.SYS_ERR); } finally { try { if (null != stmt) { stmt.close(); } if (null != conn) { conn.close(); } } catch (SQLException e) { LoggerUtil.logServerErr(e.getMessage()); } } return jsonObject.toJSONString(); }
From source file:org.perconsys.dao.implement.PostDb.java
@Override public Post create(final Post post) { KeyHolder keyh = new GeneratedKeyHolder(); final String sql = "insert into `posts` (`title`, `content`, `blog_id`, `date`) value (?, ?, ?, now()) ;"; getJdbcTemplate().update(new PreparedStatementCreator() { @Override// w ww . ja va 2s. c om public PreparedStatement createPreparedStatement(Connection conn) throws SQLException { PreparedStatement pstat = conn.prepareStatement(sql, new String[] { "id" }); pstat.setString(1, post.getTitle()); pstat.setString(2, post.getContent()); pstat.setLong(3, post.getBlog().getId()); return pstat; } }, keyh); Long id = (Long) keyh.getKey(); post.setId(id); return post; }
From source file:com.ccoe.build.dal.RawDataJDBCTemplate.java
public int create(final Plugin plugin, final int sessionID, final int projectID) { final String SQL = "insert into RBT_RAW_DATA (plugin_id, session_id, " + "project_id, duration, event_time, plugin_key) values (?, ?, ?, ?, ?, ?)"; KeyHolder keyHolder = new GeneratedKeyHolder(); jdbcTemplateObject.update(new PreparedStatementCreator() { public PreparedStatement createPreparedStatement(Connection connection) throws SQLException { PreparedStatement ps = connection.prepareStatement(SQL, new String[] { "id" }); ps.setInt(1, plugin.getId()); ps.setInt(2, sessionID);/*from ww w. j ava 2 s. c o m*/ ps.setInt(3, projectID); ps.setLong(4, plugin.getDuration()); ps.setTimestamp(5, new java.sql.Timestamp(plugin.getStartTime().getTime())); ps.setString(6, plugin.getGroupId() + ":" + plugin.getArtifactId()); return ps; } }, keyHolder); return keyHolder.getKey().intValue(); }
From source file:com.orangeandbronze.jblubble.jdbc.springframework.SpringJdbcBlobstoreService.java
@Override public int[] delete(BlobKey... blobKeys) throws BlobstoreException { try {/* w w w. j a va2s . c o m*/ return jdbcTemplate.batchUpdate(getDeleteByIdSql(), new BatchPreparedStatementSetter() { @Override public void setValues(PreparedStatement ps, int i) throws SQLException { ps.setLong(1, Long.valueOf(blobKeys[i].stringValue())); } @Override public int getBatchSize() { return blobKeys.length; } }); } catch (DataAccessException e) { throw new BlobstoreException(e); } }
From source file:org.perconsys.dao.implement.BlogDb.java
@Override public Blog create(final Blog blog) { KeyHolder keyh = new GeneratedKeyHolder(); final String sql = "insert into blogs (name, url_name, user_id) value (?, ?, ?) ;"; getJdbcTemplate().update(new PreparedStatementCreator() { @Override/* w w w .j a va 2 s . c om*/ public PreparedStatement createPreparedStatement(Connection conn) throws SQLException { PreparedStatement pstat = conn.prepareStatement(sql, new String[] { "id" }); pstat.setString(1, blog.getName()); pstat.setString(2, blog.getUrl_name()); pstat.setLong(3, blog.getUser().getId()); return pstat; } }, keyh); Long id = (Long) keyh.getKey(); blog.setId(id); return blog; }
From source file:de.iritgo.aktario.jdbc.DeleteUser.java
/** * Perform the command./*from ww w . j a v a2 s .c o m*/ */ public void perform() { if (properties.get("id") == null) { Log.logError("persist", "DeleteUser", "Missing unique id for the user to delete"); return; } UserRegistry userRegistry = Server.instance().getUserRegistry(); long userId = ((Long) properties.get("id")).longValue(); User user = userRegistry.getUser(userId); if (user == null) { Log.logError("persist", "DeleteUser", "Unable to find user with id " + userId); return; } JDBCManager jdbcManager = (JDBCManager) Engine.instance().getManager("persist.JDBCManager"); DataSource dataSource = jdbcManager.getDefaultDataSource(); Connection connection = null; PreparedStatement stmt = null; try { connection = dataSource.getConnection(); stmt = connection.prepareStatement("delete from IritgoUser where id=?"); stmt.setLong(1, userId); stmt.execute(); stmt.close(); stmt = connection.prepareStatement("delete from IritgoNamedObjects where userId=?"); stmt.setLong(1, userId); stmt.execute(); stmt.close(); Log.logVerbose("persist", "DeleteUser", "DELETE USER " + userId); } catch (SQLException x) { Log.logError("persist", "DeleteUser", "Error while storing user with id " + userId + ": " + x); } finally { DbUtils.closeQuietly(stmt); DbUtils.closeQuietly(connection); } }
From source file:dao.DirectoryAddStreamBlobQuery.java
/** * This method is used to add blobstreams for directory. * @param conn - the connection/* ww w . jav a2 s . co m*/ * @param blob - the blob stream * @param blobType - the blob type (1 - photos, 2-music, 3-video 4 - documents, 5 - archives) * @param mimeType - the mime type (image/jpeg, application/octet-stream) * @param btitle - the title for this blob * @param bsize - the size of the blob * @param zoom - the zoom for the blob (used for displaying for image/jpeg) * @param directoryId - the directoryId * @param loginId - the loginId * @param caption - the caption * Modified query to accessdate at the end * @throws Dao Exception - when an error or exception occurs while inserting this blob in DB. * **/ public void run(Connection conn, byte[] blob, int blobType, String mimeType, String btitle, long bsize, int zoom, String directoryId, String loginId, String caption) throws BaseDaoException { // long dt = new java.util.Date().getTime(); byte[] capBytes = { ' ' }; if (!RegexStrUtil.isNull(caption)) { capBytes = caption.getBytes(); } long dt = System.currentTimeMillis(); PreparedStatement s = null; String stmt = "insert into dirblob values(?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP(), ?, ?, ?, ?, CURRENT_TIMESTAMP())"; try { s = conn.prepareStatement(stmt); s.setLong(1, 0); s.setLong(2, new Long(directoryId)); s.setLong(3, new Long(loginId)); s.setInt(4, new Integer(blobType)); s.setString(5, mimeType); s.setString(6, btitle); // s.setDate(7, new Date(dt)); s.setBytes(7, blob); s.setLong(8, bsize); s.setInt(9, new Integer(zoom)); s.setBytes(10, capBytes); s.executeUpdate(); } catch (Exception e) { throw new BaseDaoException("Error adding a blob to directory query stmt " + stmt, e); } }
From source file:org.dcache.chimera.DirectoryStreamImpl.java
DirectoryStreamImpl(FsInode dir, JdbcTemplate jdbc) { _jdbc = jdbc;// w ww. j av a2 s. co m Connection connection = null; PreparedStatement ps = null; ResultSet rs; try { connection = DataSourceUtils.getConnection(_jdbc.getDataSource()); ps = connection.prepareStatement(QUERY); ps.setFetchSize(50); ps.setLong(1, dir.ino()); ps.setLong(2, dir.ino()); ps.setLong(3, dir.ino()); rs = ps.executeQuery(); } catch (SQLException ex) { JdbcUtils.closeStatement(ps); DataSourceUtils.releaseConnection(connection, _jdbc.getDataSource()); throw _jdbc.getExceptionTranslator().translate("StatementExecution", QUERY, ex); } _connection = connection; _resultSet = rs; _statement = ps; }