List of usage examples for org.apache.commons.dbcp BasicDataSource setPassword
public synchronized void setPassword(String password)
Sets the #password .
Note: this method currently has no effect once the pool has been initialized.
From source file:org.midao.jdbc.core.pool.MjdbcPoolBinder.java
/** * Returns new Pooled {@link DataSource} implementation * * In case this function won't work - use {@link #createDataSource(java.util.Properties)} * * @param driverClassName Driver Class name * @param url Database connection url//from www . j av a 2 s.c om * @param userName Database user name * @param password Database user password * @param initialSize initial pool size * @param maxActive max connection active * @return new Pooled {@link DataSource} implementation * @throws SQLException */ public static DataSource createDataSource(String driverClassName, String url, String userName, String password, int initialSize, int maxActive) throws SQLException { assertNotNull(driverClassName); assertNotNull(url); assertNotNull(userName); assertNotNull(password); BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName(driverClassName); ds.setUrl(url); ds.setUsername(userName); ds.setPassword(password); ds.setMaxActive(maxActive); ds.setInitialSize(initialSize); return ds; }
From source file:org.mskcc.cbio.portal.dao.JdbcUtil.java
private static DataSource initDataSource() { DatabaseProperties dbProperties = DatabaseProperties.getInstance(); String host = dbProperties.getDbHost(); String userName = dbProperties.getDbUser(); String password = dbProperties.getDbPassword(); String database = dbProperties.getDbName(); String url = "jdbc:mysql://" + host + "/" + database + "?user=" + userName + "&password=" + password + "&zeroDateTimeBehavior=convertToNull"; // Set up poolable data source BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName("com.mysql.jdbc.Driver"); ds.setUsername(userName);/* w w w . ja v a 2 s .c o m*/ ds.setPassword(password); ds.setUrl(url); // By pooling/reusing PreparedStatements, we get a major performance gain ds.setPoolPreparedStatements(true); ds.setMaxActive(100); activeConnectionCount = new HashMap<String, Integer>(); return ds; }
From source file:org.mzd.shap.sql.FunctionalTable.java
/** * @param args/*from w ww .j ava 2 s . com*/ */ public static void main(String[] args) throws Exception { if (args.length != 2) { throw new Exception("Usage: [func_cat.txt] [cog-to-cat.txt]"); } BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName("com.mysql.jdbc.Driver"); ds.setUrl("jdbc:mysql://localhost/Dummy"); ds.setUsername("test"); ds.setPassword("xeno12"); Connection conn = ds.getConnection(); // Get the Sequence ID list. PreparedStatement insert = null; LineNumberReader reader = null; try { reader = new LineNumberReader(new FileReader(args[0])); insert = conn.prepareStatement("INSERT INTO CogCategories (code,function,class) values (?,?,?)"); while (true) { String line = reader.readLine(); if (line == null) { break; } String[] fields = line.split("\t"); if (fields.length != 3) { throw new Exception("Bad number of fields [" + fields.length + "] for line [" + line + "]"); } insert.setString(1, fields[0]); insert.setString(2, fields[1]); insert.setString(3, fields[2]); insert.executeUpdate(); } insert.close(); reader.close(); reader = new LineNumberReader(new FileReader(args[1])); insert = conn.prepareStatement("INSERT INTO CogFunctions (accession,code) values (?,?)"); while (true) { String line = reader.readLine(); if (line == null) { break; } String[] fields = line.split("\\s+"); if (fields.length != 2) { throw new Exception("Bad number of fields [" + fields.length + "] for line [" + line + "]"); } for (char code : fields[1].toCharArray()) { insert.setString(1, fields[0]); insert.setString(2, String.valueOf(code)); insert.executeUpdate(); } } insert.close(); } finally { if (reader != null) { reader.close(); } conn.close(); ds.close(); } }
From source file:org.mzd.shap.sql.UpdateFeatureTable.java
/** * @param args// w w w. j ava 2 s . c o m */ public static void main(String[] args) throws SQLException { BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName("com.mysql.jdbc.Driver"); ds.setUrl("jdbc:mysql://localhost/BBay01a"); ds.setUsername("test"); ds.setPassword("xeno12"); Connection conn = ds.getConnection(); // Get the Sequence ID list. PreparedStatement select = null; PreparedStatement update = null; ResultSet result = null; select = conn.prepareStatement("SELECT DISTINCT SEQUENCE_ID FROM Features"); result = select.executeQuery(); List<Integer> sequenceIds = new ArrayList<Integer>(); result.beforeFirst(); while (result.next()) { sequenceIds.add(result.getInt(1)); } result.close(); select.close(); // Get the list of Feature IDs for this Sequence ID select = conn.prepareStatement("SELECT FEATURE_ID FROM Features WHERE SEQUENCE_ID=? ORDER BY start"); // Update the idx column for this feature id update = conn.prepareStatement("UPDATE Features SET featureOrder=? where FEATURE_ID=?"); for (Integer seqId : sequenceIds) { select.setInt(1, seqId); result = select.executeQuery(); int n = 0; result.beforeFirst(); while (result.next()) { int featId = result.getInt(1); update.setInt(1, n++); update.setInt(2, featId); if (update.executeUpdate() != 1) { System.out.println("Failed update [" + update.toString() + "]"); throw new SQLException(); } } result.close(); } update.close(); select.close(); conn.close(); ds.close(); }
From source file:org.nebula.service.core.DynamicDataSource.java
public void onChange(String dbUrl) { logger.info("Change target dbUrl to: " + dbUrl); Object oldDataSource = this.datasources.remove(LOOKUP_KEY); if (oldDataSource != null) { try {// w ww . jav a 2 s . c o m ((BasicDataSource) oldDataSource).close(); } catch (SQLException e) { //ignore } } BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName("com.mysql.jdbc.Driver"); dataSource.setMaxActive(jdbcMaxActive); dataSource.setMaxIdle(jdbcMaxIdle); dataSource.setInitialSize(jdbcInitialSize); dataSource.setUrl(dbUrl); dataSource.setUsername(jdbcUsername); dataSource.setPassword(jdbcPassword); dataSource.setTestOnBorrow(true); dataSource.setValidationQuery("SELECT 1"); this.datasources.put(LOOKUP_KEY, dataSource); }
From source file:org.nema.medical.mint.server.ServerConfig.java
@Bean(destroyMethod = "close") public SessionFactory sessionFactory() throws Exception { if (sessionFactory == null) { final AnnotationSessionFactoryBean annotationSessionFactoryBean = new AnnotationSessionFactoryBean(); if (StringUtils.isBlank(getConfigString("hibernate.connection.datasource"))) { // Not using JNDI data source final BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName(getConfigString("hibernate.connection.driver_class")); String url = getConfigString("hibernate.connection.url"); url = url.replace("$MINT_HOME", mintHome().getPath()); dataSource.setUrl(url);/*from w w w . j av a2 s. co m*/ dataSource.setUsername(getConfigString("hibernate.connection.username")); dataSource.setPassword(getConfigString("hibernate.connection.password")); annotationSessionFactoryBean.setDataSource(dataSource); } else { // Using a JNDI dataSource final JndiObjectFactoryBean jndiObjectFactoryBean = new JndiObjectFactoryBean(); jndiObjectFactoryBean.setExpectedType(DataSource.class); jndiObjectFactoryBean.setJndiName(getConfigString("hibernate.connection.datasource")); jndiObjectFactoryBean.afterPropertiesSet(); annotationSessionFactoryBean.setDataSource((DataSource) jndiObjectFactoryBean.getObject()); } final Properties hibernateProperties = new Properties(); hibernateProperties.put("hibernate.connection.autocommit", Boolean.TRUE); final String dialect = getConfigString("hibernate.dialect"); if (StringUtils.isNotBlank(dialect)) { hibernateProperties.put("hibernate.dialect", dialect); } final String hbm2dll = getConfigString("hibernate.hbm2ddl.auto"); hibernateProperties.put("hibernate.hbm2ddl.auto", hbm2dll == null ? "verify" : hbm2dll); hibernateProperties.put("hibernate.show_sql", "true".equalsIgnoreCase(getConfigString("hibernate.show_sql"))); hibernateProperties.put("hibernate.c3p0.max_statement", 50); hibernateProperties.put("hibernate.c3p0.maxPoolSize", 20); hibernateProperties.put("hibernate.c3p0.minPoolSize", 5); hibernateProperties.put("hibernate.c3p0.testConnectionOnCheckout", Boolean.FALSE); hibernateProperties.put("hibernate.c3p0.timeout", 600); annotationSessionFactoryBean.setHibernateProperties(hibernateProperties); annotationSessionFactoryBean.setPackagesToScan(getPackagesToScan()); annotationSessionFactoryBean.afterPropertiesSet(); sessionFactory = annotationSessionFactoryBean.getObject(); } return sessionFactory; }
From source file:org.ng200.openolympus.Application.java
@Bean public DataSource dataSource() { final BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName("org.postgresql.Driver"); dataSource.setUsername("postgres"); dataSource.setPassword(this.postgresPassword); dataSource.setUrl("jdbc:postgresql://" + this.postgresAddress + "/openolympus"); return dataSource; }
From source file:org.onecmdb.utils.wsdl.OneCMDBTransform.java
public IDataSource getDataSource() throws Exception { if (this.source != null) { Properties p = new Properties(); FileInputStream in = new FileInputStream(this.source); boolean loaded = false; try {//from w w w. j a va 2 s .c om p.loadFromXML(in); loaded = true; } catch (Throwable e) { e.printStackTrace(); } finally { in.close(); } if (!loaded) { in = new FileInputStream(this.source); try { p.load(in); } finally { in.close(); } } return (getDataSource(p)); } if (this.jdbcSource != null) { Properties p = new Properties(); FileInputStream in = new FileInputStream(this.jdbcSource); try { p.loadFromXML(in); } finally { in.close(); } BasicDataSource jdbcSrc = new BasicDataSource(); jdbcSrc.setUrl(p.getProperty("db.url")); jdbcSrc.setDriverClassName(p.getProperty("db.driverClass")); jdbcSrc.setUsername(p.getProperty("db.user")); jdbcSrc.setPassword(p.getProperty("db.password")); JDBCDataSourceWrapper src = new JDBCDataSourceWrapper(); src.setDataSource(jdbcSrc); return (src); } // Else plain file... if (fileSource == null) { throw new IOException("No data source specified!"); } if ("xml".equalsIgnoreCase(sourceType) || fileSource.endsWith(".xml")) { XMLDataSource dSource = new XMLDataSource(); dSource.addURL(new URL(fileSource)); return (dSource); } if ("csv".equalsIgnoreCase(sourceType) || fileSource.endsWith(".csv")) { CSVDataSource dSource = new CSVDataSource(); dSource.addURL(new URL("file:" + fileSource)); if (csvProperty != null) { HashMap<String, String> map = toMap(csvProperty, ","); String headerLines = map.get("headerLines"); String delimiter = map.get("delimiter"); String colTextDel = map.get("colTextDel"); if (headerLines != null) { dSource.setHeaderLines(Long.parseLong(headerLines)); } dSource.setColDelimiter(delimiter); dSource.setTextDelimiter(colTextDel); } return (dSource); } throw new IOException("Data source <" + fileSource + "> extension not supported!"); }
From source file:org.openbravo.erpCommon.modules.ImportModule.java
/** * Inserts in database the Vector<DynaBean> with its dependencies * /*ww w. ja va 2s.c o m*/ * @param dModulesToInstall * @param dependencies1 * @param newModule * @throws Exception */ private void insertDynaModulesInDB(Vector<DynaBean> dModulesToInstall, Vector<DynaBean> dependencies1, Vector<DynaBean> dbPrefix, boolean newModule) throws Exception { final Properties obProperties = new Properties(); obProperties.load(new FileInputStream(obDir + "/config/Openbravo.properties")); final String url = obProperties.getProperty("bbdd.url") + (obProperties.getProperty("bbdd.rdbms").equals("POSTGRE") ? "/" + obProperties.getProperty("bbdd.sid") : ""); final BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName(obProperties.getProperty("bbdd.driver")); ds.setUrl(url); ds.setUsername(obProperties.getProperty("bbdd.user")); ds.setPassword(obProperties.getProperty("bbdd.password")); final Connection conn = ds.getConnection(); Integer seqNo = new Integer(ImportModuleData.selectSeqNo(pool)); for (final DynaBean module : dModulesToInstall) { seqNo += 10; module.set("ISDEFAULT", "N"); module.set("STATUS", "I"); module.set("SEQNO", seqNo); module.set("UPDATE_AVAILABLE", null); module.set("UPGRADE_AVAILABLE", null); log4j.info("Inserting in DB info for module: " + module.get("NAME")); String moduleId = (String) module.get("AD_MODULE_ID"); // Clean temporary tables ImportModuleData.cleanModuleInstall(pool, moduleId); ImportModuleData.cleanModuleDBPrefixInstall(pool, moduleId); ImportModuleData.cleanModuleDependencyInstall(pool, moduleId); String type = (String) module.get("TYPE"); String applyConfigScript = "Y"; if ("T".equals(type)) { if (newModule && V3_TEMPLATE_ID.equals(moduleId)) { // When installing V3 template do not apply its config script applyConfigScript = "N"; } else { org.openbravo.model.ad.module.Module template = OBDal.getInstance() .get(org.openbravo.model.ad.module.Module.class, moduleId); applyConfigScript = template == null ? "Y" : template.isApplyConfigurationScript() ? "Y" : "N"; } } // Insert data in temporary tables ImportModuleData.insertModuleInstall(pool, moduleId, (String) module.get("NAME"), (String) module.get("VERSION"), (String) module.get("DESCRIPTION"), (String) module.get("HELP"), (String) module.get("URL"), type, (String) module.get("LICENSE"), (String) module.get("ISINDEVELOPMENT"), (String) module.get("ISDEFAULT"), seqNo.toString(), (String) module.get("JAVAPACKAGE"), (String) module.get("LICENSETYPE"), (String) module.get("AUTHOR"), (String) module.get("STATUS"), (String) module.get("UPDATE_AVAILABLE"), (String) module.get("ISTRANSLATIONREQUIRED"), (String) module.get("AD_LANGUAGE"), (String) module.get("HASCHARTOFACCOUNTS"), (String) module.get("ISTRANSLATIONMODULE"), (String) module.get("HASREFERENCEDATA"), (String) module.get("ISREGISTERED"), (String) module.get("UPDATEINFO"), (String) module.get("UPDATE_VER_ID"), (String) module.get("REFERENCEDATAINFO"), applyConfigScript); // Set installed for modules being updated ImportModuleData.setModuleUpdated(pool, (String) module.get("AD_MODULE_ID")); addLog("@ModuleInstalled@ " + module.get("NAME") + " - " + module.get("VERSION"), MSG_SUCCESS); } for (final DynaBean module : dependencies1) { ImportModuleData.insertModuleDependencyInstall(pool, (String) module.get("AD_MODULE_DEPENDENCY_ID"), (String) module.get("AD_MODULE_ID"), (String) module.get("AD_DEPENDENT_MODULE_ID"), (String) module.get("STARTVERSION"), (String) module.get("ENDVERSION"), (String) module.get("ISINCLUDED"), (String) module.get("DEPENDANT_MODULE_NAME")); } for (final DynaBean module : dbPrefix) { ImportModuleData.insertModuleDBPrefixInstall(pool, (String) module.get("AD_MODULE_DBPREFIX_ID"), (String) module.get("AD_MODULE_ID"), (String) module.get("NAME")); } conn.close(); }
From source file:org.openbravo.service.system.SystemValidationTask.java
private Platform getPlatform() { final Properties props = OBPropertiesProvider.getInstance().getOpenbravoProperties(); final BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName(props.getProperty("bbdd.driver")); if (props.getProperty("bbdd.rdbms").equals("POSTGRE")) { ds.setUrl(props.getProperty("bbdd.url") + "/" + props.getProperty("bbdd.sid")); } else {/*from www .ja v a2s. c om*/ ds.setUrl(props.getProperty("bbdd.url")); } ds.setUsername(props.getProperty("bbdd.user")); ds.setPassword(props.getProperty("bbdd.password")); return PlatformFactory.createNewPlatformInstance(ds); }