List of usage examples for java.sql PreparedStatement setInt
void setInt(int parameterIndex, int x) throws SQLException;
int
value. From source file:oobbit.orm.Users.java
public User get(int id) throws SQLException, NothingWasFoundException { PreparedStatement statement = getConnection().prepareStatement( "SELECT user_id, username, email, access_level, create_time FROM oobbit.users WHERE user_id = ?;"); statement.setInt(1, id); ResultSet query = statement.executeQuery(); if (query.next()) { User user = new User(); user.parse(query);/* w w w. j a v a 2 s . c om*/ return user; } throw new NothingWasFoundException("No user found with that id."); }
From source file:com.imagelake.control.InterfaceDAOImp.java
public Interfaces getInterfaceName(int infid) { Interfaces inf = null;/*from www . java 2 s . c o m*/ System.out.println("IIIIIIIIii " + infid); try { String sql = "SELECT * FROM interfaces WHERE interfaces_id=?"; PreparedStatement ps = DBFactory.getConnection().prepareStatement(sql); ps.setInt(1, infid); ResultSet rs = ps.executeQuery(); while (rs.next()) { System.out.println("url:" + rs.getString(2)); inf = new Interfaces(); inf.setInterface_id(rs.getInt(1)); inf.setUrl(rs.getString(2)); inf.setDisplay_name(rs.getString(3)); inf.setState(rs.getInt(4)); inf.setImg_id(rs.getInt(5)); } } catch (Exception e) { e.printStackTrace(); } return inf; }
From source file:biblivre3.acquisition.quotation.QuotationDAO.java
public ArrayList<QuotationDTO> listQuotations(int offset, int limit) { ArrayList<QuotationDTO> requestList = new ArrayList<QuotationDTO>(); Connection con = null;// ww w. j a va 2 s . c om try { con = getDataSource().getConnection(); final String sql = " SELECT * FROM acquisition_quotation " + " ORDER BY serial_quotation ASC offset ? limit ? "; final PreparedStatement pst = con.prepareStatement(sql); pst.setInt(1, offset); pst.setInt(2, limit); final ResultSet rs = pst.executeQuery(); if (rs == null) { return requestList; } while (rs.next()) { QuotationDTO dto = this.populateDto(rs); requestList.add(dto); } } catch (Exception e) { log.error(e.getMessage(), e); throw new DAOException(e.getMessage()); } finally { closeConnection(con); } return requestList; }
From source file:biospectra.taxdb.TaxonDB.java
public Taxonomy getTaxonomyByTaxid(int taxid) throws Exception { Taxonomy tax = null;//from w w w .j a v a2 s . co m PreparedStatement pstmt = null; try { pstmt = this.connection.prepareStatement(QUERY_BY_TAXID); pstmt.setInt(1, taxid); ResultSet rs = pstmt.executeQuery(); while (rs.next()) { tax = new Taxonomy(rs.getInt("taxid"), rs.getString("name"), rs.getInt("parent"), rs.getString("rank")); break; } } catch (SQLException ex) { throw ex; } finally { if (pstmt != null) { pstmt.close(); } } return tax; }
From source file:me.eccentric_nz.plugins.FatPort.FatPortCmdUtils.java
public void insertCmd(int pid, String cmd, int num, int cooldown) { try {/* www . j a v a2 s . co m*/ Connection connection = service.getConnection(); PreparedStatement statement = connection .prepareStatement("INSERT INTO commands (p_id, command, num_uses, cooldown) VALUES (?,?,?,?)"); statement.setInt(1, pid); statement.setString(2, cmd); statement.setInt(3, num); statement.setInt(4, cooldown); statement.executeUpdate(); } catch (SQLException e) { plugin.debug("Could not save command! " + e); } }
From source file:biblivre3.acquisition.quotation.QuotationDAO.java
public boolean deleteQuotation(QuotationDTO dto) { Connection conInsert = null;/* ww w. j a v a2s . co m*/ try { conInsert = getDataSource().getConnection(); final String sqlInsert = " DELETE FROM acquisition_quotation " + " WHERE serial_quotation = ?; "; PreparedStatement pstInsert = conInsert.prepareStatement(sqlInsert); pstInsert.setInt(1, dto.getSerial()); return pstInsert.executeUpdate() > 0; } catch (Exception e) { log.error(e.getMessage(), e); throw new DAOException(e.getMessage()); } finally { closeConnection(conInsert); } }
From source file:com.l2jfree.gameserver.communitybbs.bb.Post.java
public void deleteme(Topic t) { PostBBSManager.getInstance().delPostByTopic(t); Connection con = null;/*from ww w .j ava 2 s . c o m*/ try { con = L2DatabaseFactory.getInstance().getConnection(con); PreparedStatement statement = con .prepareStatement("DELETE FROM posts WHERE post_forum_id=? AND post_topic_id=?"); statement.setInt(1, t.getForumID()); statement.setInt(2, t.getID()); statement.execute(); statement.close(); } catch (Exception e) { _log.error(e.getMessage(), e); } finally { L2DatabaseFactory.close(con); } }
From source file:com.alibaba.druid.benckmark.pool.Oracle_Case4.java
private void p0(final DataSource dataSource, String name, int threadCount) throws Exception { final CountDownLatch startLatch = new CountDownLatch(1); final CountDownLatch endLatch = new CountDownLatch(threadCount); for (int i = 0; i < threadCount; ++i) { Thread thread = new Thread() { public void run() { try { startLatch.await();/*from w w w. j av a2 s .c o m*/ for (int i = 0; i < LOOP_COUNT; ++i) { Connection conn = dataSource.getConnection(); int mod = i % 500; String sql = SQL; // + " AND ROWNUM <= " + (mod + 1); PreparedStatement stmt = conn.prepareStatement(sql); stmt.setInt(1, 61); ResultSet rs = stmt.executeQuery(); int rowCount = 0; while (rs.next()) { rowCount++; } // Assert.isTrue(!rs.isClosed()); rs.close(); // Assert.isTrue(!stmt.isClosed()); stmt.close(); Assert.isTrue(stmt.isClosed()); conn.close(); Assert.isTrue(conn.isClosed()); } } catch (Exception ex) { ex.printStackTrace(); } endLatch.countDown(); } }; thread.start(); } long startMillis = System.currentTimeMillis(); long startYGC = TestUtil.getYoungGC(); long startFullGC = TestUtil.getFullGC(); startLatch.countDown(); endLatch.await(); long millis = System.currentTimeMillis() - startMillis; long ygc = TestUtil.getYoungGC() - startYGC; long fullGC = TestUtil.getFullGC() - startFullGC; System.out.println("thread " + threadCount + " " + name + " millis : " + NumberFormat.getInstance().format(millis) + ", YGC " + ygc + " FGC " + fullGC); }
From source file:org.dcache.chimera.H2FsSqlDriver.java
@Override long createTagInode(int uid, int gid, int mode, byte[] value) { final String CREATE_TAG_INODE_WITH_VALUE = "INSERT INTO t_tags_inodes (imode, inlink, iuid, igid, isize, " + "ictime, iatime, imtime, ivalue) VALUES (?,1,?,?,?,?,?,?,?)"; Timestamp now = new Timestamp(System.currentTimeMillis()); KeyHolder keyHolder = new GeneratedKeyHolder(); int rc = _jdbc.update(con -> { PreparedStatement ps = con.prepareStatement(CREATE_TAG_INODE_WITH_VALUE, Statement.RETURN_GENERATED_KEYS); ps.setInt(1, mode | UnixPermission.S_IFREG); ps.setInt(2, uid);//from www . j a v a 2 s. c o m ps.setInt(3, gid); ps.setLong(4, value.length); ps.setTimestamp(5, now); ps.setTimestamp(6, now); ps.setTimestamp(7, now); ps.setBinaryStream(8, new ByteArrayInputStream(value), value.length); return ps; }, keyHolder); if (rc != 1) { throw new JdbcUpdateAffectedIncorrectNumberOfRowsException(CREATE_TAG_INODE_WITH_VALUE, 1, rc); } /* H2 uses weird names for the column with the auto-generated key, so we cannot use the code * in the base class. */ return (Long) keyHolder.getKey(); }
From source file:biblivre3.cataloging.bibliographic.IndexDAO.java
public final boolean insert(IndexTable table, List<IndexDTO> indexList) { if (indexList == null && indexList.isEmpty()) { return false; }/*w w w. j av a 2 s. com*/ Connection con = null; try { con = getDataSource().getConnection(); StringBuilder sql = new StringBuilder(); sql.append(" INSERT INTO ").append(table.getTableName()); sql.append(" (index_word, record_serial) "); sql.append(" VALUES (?, ?);"); PreparedStatement pst = con.prepareStatement(sql.toString()); for (IndexDTO index : indexList) { pst.setString(1, StringUtils.substring(index.getWord(), 0, 511)); pst.setInt(2, index.getRecordSerial()); pst.addBatch(); } pst.executeBatch(); } catch (BatchUpdateException bue) { log.error(bue.getNextException(), bue); throw new ExceptionUser("ERROR_BIBLIO_DAO_EXCEPTION"); } catch (Exception e) { log.error(e.getMessage(), e); throw new ExceptionUser("ERROR_BIBLIO_DAO_EXCEPTION"); } finally { closeConnection(con); } return true; }