List of usage examples for java.sql PreparedStatement setLong
void setLong(int parameterIndex, long x) throws SQLException;
long
value. From source file:com.climate.oada.dao.impl.PostGISResourceDAO.java
@Override public boolean insert(LandUnit lu) { boolean retval = false; Connection conn = null;/*from w w w. jav a2 s . co m*/ try { conn = dataSource.getConnection(); PreparedStatement ps = conn.prepareStatement(INSERT_LANDUNIT_SQL); ps.setLong(ID_INDEX, lu.getUnitId()); ps.setLong(USER_ID_INDEX, lu.getUserId()); ps.setString(NAME_INDEX, lu.getName()); ps.setString(FARM_NAME_INDEX, lu.getFarmName()); ps.setString(CLIENT_NAME_INDEX, lu.getClientName()); ps.setFloat(ACRES_INDEX, lu.getAcres()); ps.setString(SOURCE_INDEX, lu.getSource()); ps.setString(OTHER_PROPS_INDEX, null); ps.setString(GEOM_INDEX, lu.getWktBoundary()); ps.executeUpdate(); ps.close(); retval = true; } catch (SQLException e) { LOG.error("Landunit insert failed " + lu.toString()); } finally { if (conn != null) { try { conn.close(); } catch (SQLException e) { LOG.error("JDBC Connection Close Failed " + e.getMessage()); } } } return retval; }
From source file:ch.newscron.encryption.ReferralManagerJUnitTest.java
@Test public void databaseTest() throws SQLException { con = ReferralManager.connect();/*from w w w . j ava 2 s.co m*/ int numberShortURLbefore = ReferralManager .getCustomerShortURLs(Long.parseLong((String) inviteData.get("custID"))).size(); boolean b = ReferralManager.insertShortURL(Long.parseLong((String) inviteData.get("custID")), shortURL); ReferralManager.disconnect(con, null); con = ReferralManager.connect(); List<CustomerShortURL> listShortURL = ReferralManager .getCustomerShortURLs(Long.parseLong((String) inviteData.get("custID"))); assertTrue(listShortURL.size() == numberShortURLbefore + 1); ReferralManager.disconnect(con, null); con = ReferralManager.connect(); PreparedStatement query = null; ResultSet rs = null; query = con.prepareStatement("SELECT * FROM ShortURL WHERE custId = ? AND shortUrl = ?"); query.setLong(1, Long.parseLong((String) inviteData.get("custID"))); query.setString(2, shortURL); rs = query.executeQuery(); int count = 0; while (rs.next()) ++count; assertTrue(count == 1); ReferralManager.disconnect(con, query, rs); }
From source file:org.tibetjungle.demo.dao.ContactDaoImpl.java
public void update(final Contact contact) { getJdbcTemplate().update("update contacts set contact_name = ?, address = ? where id = ?", new PreparedStatementSetter() { public void setValues(PreparedStatement ps) throws SQLException { ps.setString(1, contact.getName()); ps.setString(2, contact.getEmail()); ps.setLong(3, contact.getId()); }//from w w w. j a v a2s . c o m }); }
From source file:com.mobilewallet.users.dao.BalanceDAO.java
public Balance balanceInfo(long userId) { Balance w = null;//from w w w . j a v a 2 s .c om Connection con = null; PreparedStatement pstmt = null; ResultSet rs = null; try { con = dataSource.getConnection(); pstmt = con.prepareStatement(walletInfoQuery); pstmt.setLong(1, userId); rs = pstmt.executeQuery(); if (rs.next()) { w = new Balance(); w.setAmount(rs.getFloat("w_amount")); w.setTotalAmount(rs.getFloat("w_total_credits")); } } catch (Exception ex) { ex.printStackTrace(); } finally { try { if (rs != null) { rs.close(); } } catch (Exception ex) { } try { if (pstmt != null) { pstmt.close(); } } catch (Exception ex) { } try { if (con != null) { con.close(); } } catch (Exception ex) { } } return w; }
From source file:com.ccoe.build.dal.RawDataJDBCTemplate.java
public int[] batchInsert(final List<Plugin> plugins, 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 (?, ?, ?, ?, ?, ?)"; int[] updateCounts = jdbcTemplateObject.batchUpdate(SQL, new BatchPreparedStatementSetter() { public void setValues(PreparedStatement ps, int i) throws SQLException { ps.setInt(1, plugins.get(i).getId()); ps.setInt(2, sessionID);//from w w w.j a v a 2s .c o m ps.setInt(3, projectID); ps.setLong(4, plugins.get(i).getDuration()); ps.setTimestamp(5, new java.sql.Timestamp(plugins.get(i).getStartTime().getTime())); ps.setString(6, plugins.get(i).getGroupId() + ":" + plugins.get(i).getArtifactId()); } public int getBatchSize() { return plugins.size(); } }); return updateCounts; }
From source file:org.perconsys.dao.implement.CommentDb.java
@Override public Comment create(final Comment comm) { KeyHolder keyh = new GeneratedKeyHolder(); final Long target = comm.getTargetId() == 0 ? null : comm.getTargetId(); final String sql = "insert into blogs (`title`, `content`, `post_id`, `user_id`, `target_id`, `date`) " + "value (?, ?, ?, ?, ?, now()) ;"; getJdbcTemplate().update(new PreparedStatementCreator() { @Override//from ww w . j av a 2 s . c o m public PreparedStatement createPreparedStatement(Connection conn) throws SQLException { PreparedStatement pstat = conn.prepareStatement(sql, new String[] { "id" }); pstat.setString(1, comm.getTitle()); pstat.setString(2, comm.getContent()); pstat.setLong(3, comm.getPostId()); pstat.setLong(4, comm.getUser().getId()); pstat.setLong(5, target); return pstat; } }, keyh); Long id = (Long) keyh.getKey(); comm.setId(id); return comm; }
From source file:iddb.web.security.dao.SessionDAO.java
public Session get(String key, Long userId, String ip) throws EntityDoesNotExistsException { String sql = "select * from user_session where id = ? and userid = ? and ip = ?"; Connection conn = null;/*from w ww. j a va2 s. co m*/ Session session = null; try { conn = ConnectionFactory.getMasterConnection(); PreparedStatement st = conn.prepareStatement(sql); st.setString(1, key); st.setLong(2, userId); st.setString(3, ip); ResultSet rs = st.executeQuery(); if (rs.next()) { session = new Session(); loadSession(session, rs); } else { throw new EntityDoesNotExistsException("Session with key %s was not found", key); } } catch (SQLException e) { log.error("get", e); } catch (IOException e) { log.error("get", e); } finally { try { if (conn != null) conn.close(); } catch (Exception e) { } } return session; }
From source file:at.alladin.rmbt.db.dao.TestStatDao.java
@Override public int update(TestStat entity) throws SQLException { final String sql = "UPDATE test_stat SET cpu_usage = ?::json, mem_usage = ?::json, WHERE test_uid = ?"; final PreparedStatement ps = conn.prepareStatement(sql); ps.setString(1, entity.getCpuUsage().toString()); ps.setString(2, entity.getMemUsage().toString()); ps.setLong(3, entity.getTestUid()); return ps.executeUpdate(); }
From source file:iddb.web.security.dao.SessionDAO.java
public void insert(Session session) { String sql;/*from w w w . ja v a 2s . c o m*/ sql = "insert into user_session (id, userid, ip, created) values (?,?,?,?)"; Connection conn = null; try { conn = ConnectionFactory.getMasterConnection(); PreparedStatement st = conn.prepareStatement(sql); st.setString(1, session.getKey()); st.setLong(2, session.getUserId()); st.setString(3, session.getIp()); st.setTimestamp(4, new Timestamp(new Date().getTime())); st.executeUpdate(); } catch (SQLException e) { log.error("insert", e); } catch (IOException e) { log.error("insert", e); } finally { try { if (conn != null) conn.close(); } catch (Exception e) { } } }