List of usage examples for org.apache.commons.dbutils DbUtils loadDriver
public static boolean loadDriver(String driverClassName)
From source file:DbUtilsUseBeanMySQL.java
public static void main(String[] args) { Connection conn = null;/*from w ww . ja va 2s .com*/ String jdbcURL = "jdbc:mysql://localhost/octopus"; String jdbcDriver = "com.mysql.jdbc.Driver"; String user = "root"; String password = "root"; try { DbUtils.loadDriver(jdbcDriver); conn = DriverManager.getConnection(jdbcURL, user, password); QueryRunner qRunner = new QueryRunner(); List beans = (List) qRunner.query(conn, "select id, name from animals_table", new BeanListHandler(Employee.class)); for (int i = 0; i < beans.size(); i++) { Employee bean = (Employee) beans.get(i); bean.print(); } } catch (SQLException e) { // handle the exception e.printStackTrace(); } finally { DbUtils.closeQuietly(conn); } }
From source file:DbUtilsUseMapMySQL.java
public static void main(String[] args) { Connection conn = null;/*from www. j a va 2s. c o m*/ String jdbcURL = "jdbc:mysql://localhost/octopus"; String jdbcDriver = "com.mysql.jdbc.Driver"; String user = "root"; String password = "root"; try { DbUtils.loadDriver(jdbcDriver); conn = DriverManager.getConnection(jdbcURL, user, password); QueryRunner qRunner = new QueryRunner(); List mapList = (List) qRunner.query(conn, "select id, name from animals_table", new MapListHandler()); for (int i = 0; i < mapList.size(); i++) { Map map = (Map) mapList.get(i); System.out.println("id=" + map.get("id")); System.out.println("name=" + map.get("name")); System.out.println("-----------------"); } System.out.println("DbUtils_UseMap_MySQL: end."); } catch (SQLException e) { // handle the exception e.printStackTrace(); } finally { DbUtils.closeQuietly(conn); } }
From source file:com.odap.server.audit.AuditServer.java
public static void main(String[] args) { try {//from w ww. j av a 2s . c om logger.info("In main() - " + args[0]); args_cpy = args; handler = new AuditHandler(); processor = new AuditEvent.Processor(handler); config_handler = new ConfigHandler(); config_processor = new Config.Processor(config_handler); String userName = "root"; String password = args[1]; String url = "jdbc:mysql://localhost/auditcloud?zeroDateTimeBehavior=convertToNull"; keystore_password = args[2]; DbUtils.loadDriver("com.mysql.jdbc.Driver"); BoneCPConfig config = new BoneCPConfig(); // create a new configuration object config.setJdbcUrl(url); // set the JDBC url config.setUsername(userName); // set the username config.setPassword(password); // set the password connectionPool = new BoneCP(config); // setup the connection pool logger.info("Database connection established"); Configuration conf = HBaseConfiguration.create(); // conf.set("hbase.zookeeper.quorum", "server1,server2,server3"); table = new HTable(conf, "sql_audit"); Runnable simple = new Runnable() { public void run() { simple(processor, args_cpy[0]); } }; Runnable configServer = new Runnable() { public void run() { configServer(config_processor, args_cpy[0]); } }; Runnable heartBeat = new Runnable() { public void run() { checkHeartBeat(); } }; new Thread(simple).start(); new Thread(configServer).start(); new Thread(heartBeat).start(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.neu.edu.DAO.DAO.java
public DAO() { driver = "com.mysql.jdbc.Driver"; dburl = "jdbc:mysql://projectclouddb.c5fzde1wpjxu.us-west-2.rds.amazonaws.com:3306/cloud_project"; dbuser = "awsuser"; dbpassword = "awspassword"; DbUtils.loadDriver(driver); }
From source file:com.me.DAO.DAO1.java
public DAO1() { driver = "com.mysql.jdbc.Driver"; dburl = "jdbc:mysql://localhost:3306/moviedb"; dbuser = "root"; dbpassword = "Windows@123"; DbUtils.loadDriver(driver); }
From source file:com.ouc.cpss.dao.BaseDao.java
/** * // w w w . j a v a 2 s. c om * * @return */ public Connection getConnection() { Connection conn = null; String jdbcURL = "jdbc:mysql://localhost:3306/cpss? useUnicode=true&characterEncoding=UTF8"; String jdbcDriver = "com.mysql.jdbc.Driver"; String user = "root"; String password = "527611"; try { //DbUtils DbUtils.loadDriver(jdbcDriver); conn = DriverManager.getConnection(jdbcURL, user, password); } catch (SQLException e) { e.printStackTrace(); } return conn; }
From source file:de.unibremen.informatik.tdki.combo.data.DBConnPool.java
public Connection getConnection() { if (connection != null) return connection; switch (config.getDb()) { case DB2://www .j a v a 2s. c o m assert DbUtils.loadDriver("com.ibm.db2.jcc.DB2Driver"); break; case POSTGRES: break; } try { connection = DriverManager.getConnection(config.getUrl(), config.getUsername(), config.getPassword()); } catch (SQLException ex) { throw new RuntimeException(ex); } return connection; }
From source file:de.unibremen.informatik.tdki.combo.data.JdbcTemplate.java
public JdbcTemplate(String url, String user, String password) { assert DbUtils.loadDriver("com.ibm.db2.jcc.DB2Driver"); try {// w w w . ja va 2s. co m connection = DriverManager.getConnection(url, user, password); qRunner = new QueryRunner(); } catch (SQLException ex) { throw new RuntimeException(ex); } }
From source file:genepi.db.mysql.MySqlConnector.java
@Override public void connect() throws SQLException { log.debug("Establishing connection to " + user + "@" + host + ":" + port); if (DbUtils.loadDriver("com.mysql.jdbc.Driver")) { try {/*from w ww.j ava 2s.c o m*/ dataSource = new BasicDataSource(); dataSource.setDriverClassName("com.mysql.jdbc.Driver"); dataSource.setUrl("jdbc:mysql://" + host + "/" + database + "?autoReconnect=true&allowMultiQueries=true&rewriteBatchedStatements=true"); dataSource.setUsername(user); dataSource.setPassword(password); dataSource.setMaxActive(10); dataSource.setMaxWait(10000); dataSource.setMaxIdle(10); dataSource.setDefaultAutoCommit(true); } catch (Exception e) { e.printStackTrace(); } } else { System.out.println("MySQL Driver class not found."); } }
From source file:framework.retrieval.engine.index.all.database.impl.rdAbstract.DefaultRDatabaseIndexAllImpl.java
/** * ??/*from ww w . j a va 2 s . c o m*/ * * @return */ private Connection getConnection() { Connection conn = null; try { String default_retrieval_database_choose_class = DefaultRetrievalProperties .getDefault_retrieval_database_choose_class(); String[] classAndMethod = default_retrieval_database_choose_class.split(":"); String className = classAndMethod[0]; String methodName = null; if (classAndMethod.length == 1) { methodName = "loadDatabaseLink"; } else { methodName = classAndMethod[1]; } // ?? DatabaseLink databaseLink = (DatabaseLink) ReflectUtil.invokeMethod(className, methodName); DbUtils.loadDriver(databaseLink.getJdbcDriver()); conn = DriverManager.getConnection(databaseLink.getJdbcUrl(), databaseLink.getJdbcUser(), databaseLink.getJdbcPassword()); } catch (SQLException e) { throw new RetrievalIndexException(e); } return conn; }