List of usage examples for org.apache.commons.dbutils.handlers ScalarHandler ScalarHandler
public ScalarHandler()
From source file:magrathea.marvin.desktop.user.dao.DerbyDAO.DerbyUserDAO.java
@Override public long insertUser(User user) { try {// w w w . jav a 2 s. c om long id = dbAccess.insert(con, "INSERT INTO \"User\"(nickname,password,email,administrator)" + " VALUES (?,?,?,?)", new ScalarHandler<BigDecimal>(), user.getNickname(), user.getPassword(), user.getEmail(), user.isAdministrator()).longValue(); return id; } catch (Exception e) { e.printStackTrace(); } return -1L; }
From source file:com.demo.db.dao.impl.DriverAuditDaoImpl.java
@Override public DriverAudit insert(DriverAudit driverAudit) { QueryRunner queryRunner = dbHelper.getRunner(); try {//from w w w.j a v a 2 s .com queryRunner.insert(dbHelper.getConnection(), "insert into demo_driver_audit(uuid, driver_id) values(UNHEX(?), ?)", new ScalarHandler<String>(), new Object[] { driverAudit.getUuid(), driverAudit.getDriverId() }); } catch (SQLException e) { String methodName = Thread.currentThread().getStackTrace()[1].getMethodName(); logger.error("{}??{}", methodName, driverAudit); throw new RuntimeException("??", e); } return driverAudit; }
From source file:cn.itcast.bbs.dao.ReplyDao.java
public int countReplyByTopic(int id) throws SQLException { QueryRunner runner = new QueryRunner(JdbcUtil.getDataSource()); String sql = "select count(*) from reply where topic_id = ?;"; Long cnt = runner.query(sql, new ScalarHandler(), id); return cnt.intValue(); }
From source file:cn.itcast.bbs.dao.TopicDao.java
public int countTopicByType(int id) throws SQLException { QueryRunner runner = new QueryRunner(JdbcUtil.getDataSource()); String sql = "select count(*) from topic where type_id = ?;"; Long cnt = runner.query(sql, new ScalarHandler(), id); return cnt.intValue(); }
From source file:com.ruihu.easyshop.user.dao.UserDao.java
/** * check user list/* w w w. j a v a2 s. com*/ * @param loginname */ public boolean ajaxValidateLoginname(String loginname) throws SQLException { String sql = "select count(1) from t_user where loginname=?"; Number number = (Number) qr.query(sql, new ScalarHandler(), loginname); return number.intValue() == 0; }
From source file:com.ruihu.easyshop.order.dao.OrderDao.java
public int findStatus(String oid) throws SQLException { String sql = "select status from t_order where oid=?"; Number number = (Number) qr.query(sql, new ScalarHandler(), oid); return number.intValue(); }
From source file:com.libraryloan.DerbyBookDAO.java
@Override public long insertBook(Book book) { try {//w ww. ja v a 2 s . co m long id = dbAccess.insert(connection, "INSERT INTO Books (name, authors, publishedYear, available) VALUES (?, ?, ?, ?)", new ScalarHandler<BigDecimal>(), book.getName(), book.getAuthors(), book.getPublishedYear(), book.isAvailable()).longValue(); return id; } catch (Exception e) { e.printStackTrace(); } return -1L; }
From source file:io.seqware.pipeline.plugins.sanity.checks.DB_Check.java
@Override public boolean check(QueryRunner qRunner, Metadata metadataWS) throws SQLException { if (qRunner == null) { System.err.println("Warning: No or invalid SeqWare metadb settings"); return true; }// w ww . ja va 2 s.co m Object executeQuery = qRunner.executeQuery("select count(*) from processing;", new ScalarHandler()); return true; }
From source file:com.gs.obevo.db.impl.platforms.db2.Db2SqlExecutor.java
/** * Package-private for unit testing only. *//* www . j a v a2 s . c o m*/ static String getCurrentPathSql(Connection conn, JdbcHelper jdbc, ImmutableSet<PhysicalSchema> physicalSchemas) { String path = jdbc.query(conn, "select current path from sysibm.sysdummy1", new ScalarHandler<String>()); MutableList<String> currentSchemaPathList = Lists.mutable.of(path.split(",")) .collect(new Function<String, String>() { @Override public String valueOf(String object) { if (object.startsWith("\"") && object.endsWith("\"")) { return object.substring(1, object.length() - 1); } else { return object; } } }); // Rules on constructing this "set path" command: // 1) The existing default path must come first (respecting the existing connection), followed by the // schemas in our environment. The default path must take precedence. // 2) We cannot have duplicate schemas listed in the "set path" call; i.e. in case the schemas in our // environment config are already in the default schema. // // Given these two requirements, we use a LinkedHashSet LinkedHashSet<String> currentSchemaPaths = new LinkedHashSet(currentSchemaPathList); currentSchemaPaths.addAll(physicalSchemas.collect(PhysicalSchema.TO_PHYSICAL_NAME).castToSet()); // This is needed to work w/ stored procedures // Ideally, we'd use "set current path current path, " + physicalSchemaList // However, we can't set this multiple times in a connection, as we can't have dupes in "current path" // Ideally, we could use BasicDataSource.initConnectionSqls, but this does not interoperate w/ the LDAP // datasource for JNDI-JDBC return "set path " + CollectionAdapter.adapt(currentSchemaPaths).makeString(","); }
From source file:com.ruihu.easyshop.user.dao.UserDao.java
/** * check email list/*from ww w . java 2s. co m*/ * @param email * @return * @throws SQLException */ public boolean ajaxValidateEmail(String email) throws SQLException { String sql = "select count(1) from t_user where email=?"; Number number = (Number) qr.query(sql, new ScalarHandler(), email); //check user list if it equal 0, return null return number.intValue() == 0; }