Example usage for org.springframework.jdbc.core JdbcTemplate JdbcTemplate

List of usage examples for org.springframework.jdbc.core JdbcTemplate JdbcTemplate

Introduction

In this page you can find the example usage for org.springframework.jdbc.core JdbcTemplate JdbcTemplate.

Prototype

public JdbcTemplate(DataSource dataSource) 

Source Link

Document

Construct a new JdbcTemplate, given a DataSource to obtain connections from.

Usage

From source file:org.beangle.ems.avatar.service.DataBaseAvatarBase.java

public void setDataSource(DataSource dataSource) {
    if (null != dataSource) {
        jdbcTemplate = new JdbcTemplate(dataSource);
    } else {/*from  w ww.ja v a 2s  . c  o  m*/
        jdbcTemplate = null;
    }
}

From source file:Implement.DAO.CommonDAOImpl.java

public CommonDAOImpl(DataSource dataSource) {
    jdbcTemplate = new JdbcTemplate(dataSource);
    this.dataSource = dataSource;
    //        simpleJdbcCall = new SimpleJdbcCall(dataSource);
}

From source file:gov.nih.nci.cabig.ctms.tools.configuration.DatabaseBackedConfigurationTest.java

@Override
protected void setUp() throws Exception {
    super.setUp();
    sessionFactory = new AnnotationConfiguration().addAnnotatedClass(DefaultConfigurationEntry.class)
            .addAnnotatedClass(AlternateConfigurationEntry.class)
            .setProperty("hibernate.connection.driver_class", "org.hsqldb.jdbcDriver")
            .setProperty("hibernate.connection.url", "jdbc:hsqldb:mem:test" + Math.random())
            .setProperty("hibernate.connection.username", "sa").setProperty("hibernate.connection.password", "")
            .buildSessionFactory();//ww  w .  ja  v  a 2  s .  c om
    stubListener = new StubConfigurationListener();
    configuration = new ExampleConfiguration();
    configuration.setSessionFactory(sessionFactory);
    configuration.addConfigurationListener(stubListener);
    altConfiguration = new AlternateConfiguration();
    altConfiguration.setSessionFactory(sessionFactory);
    SingleConnectionDataSource ds = new SingleConnectionDataSource(sessionFactory.openSession().connection(),
            false);
    ds.setAutoCommit(true);
    jdbc = new JdbcTemplate(ds);

    for (String table : new String[] { DEFAULT_TABLE, ALT_TABLE }) {
        jdbc.execute(String.format(
                "CREATE TABLE %s (key VARCHAR(255) PRIMARY KEY, value VARCHAR(255), version INTEGER DEFAULT '0' NOT NULL)",
                table));
    }
}

From source file:com.rplt.studioMusik.member.MemberDAO.java

@Override
public int validateLogin(String pUsername, String pPassword) {
    List<Member> memberList = new ArrayList<Member>();

    String sql = "SELECT * FROM member_studio_musik WHERE username_member = ?";

    sql = "SELECT * FROM `studiomusik`.`member_studio_musik` WHERE `USERNAME_MEMBER` = ?";

    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    memberList = jdbcTemplate.query(sql, new Object[] { pUsername.toUpperCase() }, new MemberRowMapper());

    if (!memberList.isEmpty()) {
        String username = memberList.get(0).getmUsernameMember();
        String password = memberList.get(0).getmPaswordMember();
        if (pUsername.equalsIgnoreCase(username) && pPassword.equals(password)) {
            return 2;
        } else {/* w w w .  ja  va2s . com*/
            System.out.println("WRONG USERNAME/PASSWORD/ROLE");
            return 1;
        }
    } else {
        System.out.println("UNREGISTERED USERNAME");
        return 0;
    }

}

From source file:com.emc.ecs.sync.service.MySQLDbService.java

@Override
protected JdbcTemplate createJdbcTemplate() {
    BasicDataSource ds = new BasicDataSource();
    ds.setUrl(connectString);//ww  w  .  jav a2 s  .co  m
    ds.addConnectionProperty("characterEncoding", "UTF-8");
    if (username != null)
        ds.setUsername(username);
    if (password != null)
        ds.setPassword(password);
    ds.setMaxActive(1000);
    ds.setMaxIdle(1000);
    ds.setMaxOpenPreparedStatements(1000);
    ds.setPoolPreparedStatements(true);
    return new JdbcTemplate(ds);
}

From source file:com.googlecode.flyway.core.dbsupport.oracle.OracleDbSupportMediumTest.java

/**
 * Tests that the current schema for a proxy connection with conn_user[schema_user] is schema_user and not conn_user;
 *///from w ww.  ja v  a  2s  .  c om
@Test
public void currentSchemaWithProxy() {
    String currentSchema = new OracleDbSupport(new JdbcTemplate(proxyUserDataSource)).getCurrentSchema();
    assertEquals(userName.toUpperCase(), currentSchema);
}

From source file:com.emergya.openfleetservices.importer.ddbb.JDBCConnector.java

@Autowired
final public void setDataSource(final DataSource dataSource) {
    this.simpleJdbcTemplate = new JdbcTemplate(dataSource);
    this.namedJdbcTemplate = new NamedParameterJdbcTemplate(dataSource);
}

From source file:com.beezas.dao.ContactDaoImpl.java

@Override
public List<ContDrpDwns> getContactTyp() {
    List contactNam = new ArrayList();
    String sql = "SELECT * FROM CONTACTTYPE";
    jdbcTemplate = new JdbcTemplate(dataSource);
    contactNam = jdbcTemplate.query(sql, new ContDrpDwnRowMapper());
    System.out.println("Present in DaoImpl conttyp values " + contactNam);
    return contactNam;
}

From source file:edu.jhuapl.openessence.web.util.MapQueryUtil.java

public int performDelete(OeDataEntrySource mapLayerDataEntrySource, Object current_time,
        String postgresCleanup) {
    JdbcTemplate pgdb = new JdbcTemplate(mapDataSource);
    String sql = "delete from " + mapLayerDataEntrySource.getTableName()
            + " where ? > time_requested + interval '" + postgresCleanup + "'";
    log.debug(sql);//w ww .j av a  2s. c  om
    return pgdb.update(sql, current_time);
}

From source file:com.googlecode.flyway.maven.AbstractFlywayMojoTest.java

/**
 * Asserts that this mojo does not leak DB connections when executed.
 *
 * @param mojo The mojo to check.//  w  w w.j  a v a  2  s .co m
 */
private void assertNoConnectionLeak(AbstractFlywayMojo mojo) throws Exception {
    mojo.driver = "org.h2.Driver";
    mojo.url = "jdbc:h2:mem:flyway_leak_test";
    mojo.user = "SA";

    try {
        mojo.execute();
    } catch (Exception e) {
        // Ignoring. The exception is not what we're testing.
    }

    BasicDataSource dataSource = mojo.createDataSource();
    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    H2DbSupport h2DbSupport = new H2DbSupport(jdbcTemplate);
    boolean tableStillPresent = h2DbSupport.tableExists(h2DbSupport.getCurrentSchema(), "schema_version");
    dataSource.close();
    assertFalse(tableStillPresent);
}