Example usage for org.apache.commons.dbcp BasicDataSource setUsername

List of usage examples for org.apache.commons.dbcp BasicDataSource setUsername

Introduction

In this page you can find the example usage for org.apache.commons.dbcp BasicDataSource setUsername.

Prototype

public synchronized void setUsername(String username) 

Source Link

Document

Sets the #username .

Note: this method currently has no effect once the pool has been initialized.

Usage

From source file:mx.com.pixup.portal.demo.DemoDisqueraUpdate.java

public static void main(String[] args) {
    System.out.println("BIENVENIDO A PIXUP");
    System.out.println("Mantenimiento catlogo disquera");
    System.out.println("Actualizacin de Disquera");

    InputStreamReader isr = new InputStreamReader(System.in);
    BufferedReader br = new BufferedReader(isr);
    Connection connection = null;
    Statement statement = null;/*from ww w  . j a v  a 2  s  . co  m*/
    ResultSet resultSet = null;
    try {
        BasicDataSource dataSource = new BasicDataSource();
        dataSource.setDriverClassName("com.mysql.jdbc.Driver");
        dataSource.setUsername("root");
        dataSource.setPassword("admin");
        dataSource.setUrl("jdbc:mysql://127.0.0.1:3306/pixup");

        connection = dataSource.getConnection();
        statement = connection.createStatement();

        String sql = "select id, nombre from disquera order by nombre";

        resultSet = statement.executeQuery(sql);

        System.out.println("Id Disquera: \t Nombre Disquera");
        while (resultSet.next()) {
            System.out.println(resultSet.getInt("id") + " \t " + resultSet.getString("nombre"));
        }

        System.out.println("Proporcione el id de la disquera a actualizar: ");
        String idDisquera = br.readLine();

        System.out.println("Proporcione el nuevo nombre de la disquera: ");
        String nombreDisquera = br.readLine();

        sql = "update disquera set nombre = '" + nombreDisquera + "' where id = " + idDisquera;

        statement.execute(sql);

        System.out.println("Disqueras Actualizadas:");

        sql = "select id, nombre from disquera order by nombre desc";

        resultSet = statement.executeQuery(sql);

        System.out.println("Id Disquera: \t Nombre Disquera");
        while (resultSet.next()) {
            System.out.println(resultSet.getInt("id") + " \t " + resultSet.getString("nombre"));
        }

    } catch (Exception e) {
        System.out.println("Error en el sistema, intente ms tarde!!");
    } finally {
        if (resultSet != null) {
            try {
                resultSet.close();
            } catch (Exception e) {
            }
        }
        if (statement != null) {
            try {
                statement.close();
            } catch (Exception e) {
            }
        }
        if (connection != null) {
            try {
                connection.close();
            } catch (Exception e) {
            }
        }
    }
}

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  w w .j  av  a2 s. 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:aplikasi.config.KoneksiDB.java

public static DataSource getDataSource() {
    BasicDataSource ds = new BasicDataSource();
    ds.setUsername("root");
    ds.setPassword("admin");
    ds.setUrl("jdbc:mysql://localhost:3306/sipmi");
    ds.setDriverClassName("org.mariadb.jdbc.Driver");
    return ds;// ww w . ja  v  a2 s. c o  m
}

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.taobao.tddl.jdbc.group.testutil.DataSourceFactory.java

public static DataSource getMySQLDataSource(int num) {
    if (num > 3)
        num = 1;//from w w  w .j a v  a2s.com
    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;

}

From source file:com.taobao.tddl.jdbc.group.testutil.DataSourceFactory.java

public static DataSource getLocalMySQLDataSource(int num) {
    if (num > 3)
        num = 1;/*from ww  w  . j  a  v a 2  s .  c  om*/
    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName("com.mysql.jdbc.Driver");
    ds.setUsername("root");
    ds.setPassword("zhh");
    ds.setUrl("jdbc:mysql://localhost/group_test_" + num);
    return ds;

}

From source file:br.com.linuxgames.model.dao.core.LinuxGamesDataSource.java

private static DataSource setupDataSource() {
    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName("com.mysql.jdbc.Driver");
    ds.setUsername("boaglio_linuxgam");
    ds.setPassword("boaglio_linuxgam");
    ds.setUrl("jdbc:mysql://localhost/linuxgames");
    return ds;//from w w w.ja v  a 2s.co m
}

From source file:com.surveypanel.form.TestHelper.java

public static DataSource getDataSource() {
    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName("com.mysql.jdbc.Driver");
    ds.setUsername("root");
    ds.setPassword("halflife");
    ds.setUrl(/*  w  ww  .  ja  v a  2s.  c  o m*/
            "jdbc:mysql://localhost:3306/surveypanel?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8");
    return ds;
}

From source file:com.stratelia.silverpeas.silverStatisticsPeas.control.PerfVolumeTest.java

@BeforeClass
public static void setupDataSource() throws NamingException {
    SimpleMemoryContextFactory.setUpAsInitialContext();
    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName("org.postgresql.Driver");
    ds.setUsername("postgres");
    ds.setPassword("postgres");
    ds.setUrl("jdbc:postgresql://localhost:5432/extranet");
    InitialContext ic = new InitialContext();
    ic.bind("java:/datasources/silverpeas-jdbc", ds);
    ic.bind("java:/datasources/DocumentStoreDS", ds);
}