List of usage examples for org.apache.commons.dbcp BasicDataSource setDriverClassName
public synchronized void setDriverClassName(String driverClassName)
Sets the jdbc driver class name.
Note: this method currently has no effect once the pool has been initialized.
From source file:com.gnizr.db.dao.util.MySQLDBExport.java
public static void main(String[] args) throws Exception { BasicDataSource dataSource = new BasicDataSource(); dataSource.setUsername("gnizr"); dataSource.setPassword("gnizr"); dataSource.setUrl("jdbc:mysql://localhost/gnizr_db"); dataSource.setDriverClassName("com.mysql.jdbc.Driver"); IDatabaseConnection dc = new DatabaseConnection(dataSource.getConnection()); DatabaseConfig config = dc.getConfig(); config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new MySqlDataTypeFactory()); // full database export IDataSet fullDataSet = dc.createDataSet(); FlatXmlDataSet.write(fullDataSet, new FileOutputStream("full.xml")); }
From source file:ch.aranea.test.SparkCRUD.java
public static void main(String[] args) throws Exception { final BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName("org.h2.Driver"); ds.setUrl("jdbc:h2:tcp://localhost/~/test"); ds.setUsername("sa"); ds.setPassword(""); final DSLContext ctx = DSL.using(ds, SQLDialect.H2); // Creates a new book resource, will return the ID to the created resource // author and title are sent as query parameters e.g. /books?author=Foo&title=Bar post("/books", (request, response) -> { AuthorRecord author = upsertAuthor(ctx, request); BookRecord book = ctx.newRecord(BOOK); book.setAuthorId(author.getId()); book.setTitle(request.queryParams("title")); book.store();//from w ww. j a va 2s. c o m response.status(201); // 201 Created return book.getId(); }); // Gets the book resource for the provided id get("/books/:id", (request, response) -> { Record2<String, String> book = ctx.select(BOOK.TITLE, AUTHOR.NAME).from(BOOK).join(AUTHOR) .on(BOOK.AUTHOR_ID.eq(AUTHOR.ID)) .where(BOOK.ID.eq(BOOK.ID.getDataType().convert(request.params(":id")))).fetchOne(); if (book != null) { return "Title: " + book.value1() + ", Author: " + book.value2(); } else { response.status(404); // 404 Not found return "Book not found"; } }); // Updates the book resource for the provided id with new information // author and title are sent as query parameters e.g. /books/<id>?author=Foo&title=Bar put("/books/:id", (request, response) -> { BookRecord book = ctx.selectFrom(BOOK) .where(BOOK.ID.eq(BOOK.ID.getDataType().convert(request.params(":id")))).fetchOne(); if (book != null) { AuthorRecord author = upsertAuthor(ctx, request); String newAuthor = request.queryParams("author"); String newTitle = request.queryParams("title"); if (newAuthor != null) { book.setAuthorId(author.getId()); } if (newTitle != null) { book.setTitle(newTitle); } book.update(); return "Book with id '" + book.getId() + "' updated"; } else { response.status(404); // 404 Not found return "Book not found"; } }); // Deletes the book resource for the provided id delete("/books/:id", (request, response) -> { BookRecord book = ctx.deleteFrom(BOOK) .where(BOOK.ID.eq(BOOK.ID.getDataType().convert(request.params(":id")))).returning().fetchOne(); if (book != null) { return "Book with id '" + book.getId() + "' deleted"; } else { response.status(404); // 404 Not found return "Book not found"; } }); // Gets all available book resources get("/books", (request, response) -> { return ctx.selectFrom(BOOK).fetch().formatJSON(); }); }
From source file:DynaBeansExampleV2.java
private static Connection getConnection() throws Exception { BasicDataSource bds = new BasicDataSource(); bds.setDriverClassName("com.mysql.jdbc.Driver"); bds.setUrl("jdbc:mysql://localhost/commons"); bds.setUsername("root"); bds.setPassword(""); //bds.setInitialSize(5); return bds.getConnection(); }
From source file:DynaBeansExampleV3.java
private static Connection getConnection() throws Exception { BasicDataSource bds = new BasicDataSource(); bds.setDriverClassName("com.mysql.jdbc.Driver"); bds.setUrl("jdbc:mysql://localhost/commons"); bds.setUsername("root"); bds.setPassword(""); // bds.setInitialSize(5); return bds.getConnection(); }
From source file:com.github.ipan97.belajar.hashMD5.application.App.java
public static DataSource getDataSource() { BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName("com.mysql.jdbc.Driver"); dataSource.setUrl("jdbc:mysql://localhost:3306/belajar"); //set user database dataSource.setUsername("root"); //set password dataSource.setPassword("admin"); return dataSource; }
From source file:com.devwebsphere.wxs.jdbcloader.TestJDBCLoader.java
@BeforeClass static void setup() throws Exception { Class.forName(EmbeddedDriver.class.getName()); BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName(EmbeddedDriver.class.getName()); ds.setUrl("jdbc:derby:derbyDB;create=true"); Connection connTest = ds.getConnection(); Assert.assertNotNull(connTest);// ww w . ja v a2 s. co m connTest.close(); }
From source file:com.weibo.datasys.parser.sql.DBConnectionFactory.java
public static void init() { BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName(ConfigFactory.getString("jdbc.driverClassName")); dataSource.setUrl(ConfigFactory.getString("jdbc.url")); dataSource.setUsername(ConfigFactory.getString("jdbc.username")); dataSource.setPassword(ConfigFactory.getString("jdbc.password")); dataSource.setInitialSize(ConfigFactory.getInt("jdbc.initialSize", 1)); dataSource.setMinIdle(ConfigFactory.getInt("jdbc.minIdle", 2)); dataSource.setMaxIdle(ConfigFactory.getInt("jdbc.maxIdle", 10)); dataSource.setMaxWait(ConfigFactory.getInt("jdbc.maxWait", 1000)); dataSource.setMaxActive(ConfigFactory.getInt("jdbc.maxActive", 2)); dataSource.addConnectionProperty("autoReconnect", "true"); // ??/*www . j a v a 2 s . co m*/ dataSource.setTestWhileIdle(true); // ?sql? dataSource.setValidationQuery("select 'test'"); // ? dataSource.setValidationQueryTimeout(5000); // dataSource.setTimeBetweenEvictionRunsMillis(3600000); // ?? dataSource.setMinEvictableIdleTimeMillis(3600000); ds = dataSource; }
From source file:com.dangdang.ddframe.rdb.transaction.soft.AsyncJobMain.java
private static DataSource createDataSource(final String dataSourceName) { BasicDataSource result = new BasicDataSource(); result.setDriverClassName("com.mysql.jdbc.Driver"); result.setUrl(String.format("jdbc:mysql://localhost:3306/%s", dataSourceName)); result.setUsername("root"); result.setPassword(""); return result; }
From source file:com.dangdang.ddframe.rdb.transaction.soft.AsyncJobMain.java
private static DataSource createTransactionLogDataSource() { BasicDataSource result = new BasicDataSource(); result.setDriverClassName("com.mysql.jdbc.Driver"); result.setUrl("jdbc:mysql://localhost:3306/trans_log"); result.setUsername("root"); result.setPassword(""); return result; }
From source file:com.taobao.tddl.jdbc.group.testutil.DataSourceFactory.java
public static DataSource getMySQLDataSource(int num) { if (num > 3) num = 1;/*from w w w . j av a2s .c o m*/ BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName("com.mysql.jdbc.Driver"); ds.setUsername("tddl"); ds.setPassword("tddl"); ds.setUrl("jdbc:mysql://127.0.0.1:3306/group_test_" + num); return ds; }