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:com.dai.dao.JogadorEquipaAdversariaDaoImpl.java

@Override
public void alteraPosicaoJEA(int idJEA, String novaPosicao) {
    String sql = "UPDATE jogadorEquipaAdversaria set posicaoJogador = ? where idJogadorEquipaAdversaria = "
            + idJEA;//from   ww w.ja v  a 2s  .c o m
    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);

    jdbcTemplate.update(sql, new Object[] { novaPosicao });
}

From source file:com.univocity.articles.dumpload.databases.Database.java

/**
 * Initializes this Database object by creating a {@link DataSource} to provide connections to your database.
 * Tables will be created automatically if required.
 *
 * @param tablesToCreate a sequence of table names to create in this database, if they have not been created yet
 * @param connectionUrl the JDBC URL to use for accessing the {@link java.sql.DriverManager}
 * @param username the username to connect to the database
 * @param password the password of the given username, if required
 *//*from  w  w  w  .  j a  v  a 2s  .  c o  m*/
void initialize(String tablesToCreate, String connectionUrl, String username, String password) {
    try {
        Class.forName(getDriverClassName());
        DataSource dataSource = new SingleConnectionDataSource(connectionUrl, username, password, true);
        this.jdbcTemplate = new JdbcTemplate(dataSource);

    } catch (Exception ex) {
        throw new IllegalStateException(
                "Error creating database using scripts for database " + getDatabaseName(), ex);
    }

    if (tablesToCreate != null) {
        initializeDatabase(tablesToCreate);
    }
}

From source file:aos.camel.InventoryServiceTest.java

@Before
public void setup() throws Exception {
    DataSource ds = context.getRegistry().lookup("inventoryDB", DataSource.class);
    jdbc = new JdbcTemplate(ds);
}

From source file:au.com.jwatmuff.genericdb.p2p.DatabaseUpdateStore.java

private DatabaseUpdateStore(BasicDataSource dataSource) {
    template = new JdbcTemplate(dataSource);
    template.update("CREATE TABLE IF NOT EXISTS update_log (" + "data BLOB" + ")");
}

From source file:org.cloudfoundry.identity.uaa.audit.JdbcAuditServiceTests.java

@Before
public void createService() throws Exception {
    template = new JdbcTemplate(dataSource);
    auditService = new JdbcAuditService(dataSource);
    template.execute(/*from  ww w  .j av a  2s.  com*/
            "DELETE FROM sec_audit WHERE principal_id='1' or principal_id='clientA' or principal_id='clientB'");
    authDetails = "1.1.1.1";
}

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

@Override
public List<EventDates> getEventDates() {
    List eventDatesList = new ArrayList();
    String sql = "select event_date from events";
    jdbcTemplate = new JdbcTemplate(dataSource);
    eventDatesList = jdbcTemplate.query(sql, new EventDatesRowMapper());
    return eventDatesList;
}

From source file:com.exploringspatial.dao.impl.ConflictDaoImpl.java

@PostConstruct
public void init() {
    jdbcTemplate = new JdbcTemplate(dataSource);
    namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(dataSource);
    selectSql = "SELECT  ".concat("GWNO, ").concat("EVENT_ID_CNTY, ").concat("EVENT_ID_NO_CNTY, ")
            .concat("EVENT_DATE, ").concat("YEAR, ").concat("TIME_PRECISION, ").concat("EVENT_TYPE, ")
            .concat("ACTOR1, ").concat("ALLY_ACTOR_1, ").concat("INTER1, ").concat("ACTOR2, ")
            .concat("ALLY_ACTOR_2, ").concat("INTER2, ").concat("INTERACTION, ").concat("COUNTRY, ")
            .concat("ADMIN1, ").concat("ADMIN2, ").concat("ADMIN3, ").concat("LOCATION, ").concat("LATITUDE, ")
            .concat("LONGITUDE, ").concat("GEO_PRECIS, ").concat("SOURCE, ").concat("NOTES, ")
            .concat("FATALITIES FROM CONFLICT ");
    insertSql = "INSERT INTO CONFLICT (".concat("GWNO, ").concat("EVENT_ID_CNTY, ").concat("EVENT_ID_NO_CNTY, ")
            .concat("EVENT_DATE, ").concat("YEAR, ").concat("TIME_PRECISION, ").concat("EVENT_TYPE, ")
            .concat("ACTOR1, ").concat("ALLY_ACTOR_1, ").concat("INTER1, ").concat("ACTOR2, ")
            .concat("ALLY_ACTOR_2, ").concat("INTER2, ").concat("INTERACTION, ").concat("COUNTRY, ")
            .concat("ADMIN1, ").concat("ADMIN2, ").concat("ADMIN3, ").concat("LOCATION, ").concat("LATITUDE, ")
            .concat("LONGITUDE, ").concat("GEO_PRECIS, ").concat("SOURCE, ").concat("NOTES, ")
            .concat("FATALITIES) VALUES (:gwno, :event_id_cnty, :eventId, :eventDate, :year, :timePrecision, :eventType, ")
            .concat(":actor1, :allyActor1, :inter1, :actor2, :allyActor2, :inter2, :interaction, :country, ")
            .concat(":admin1, :admin2, :admin3, :location, :latitude, :longitude, :geoPrecision, :source, ")
            .concat(":notes, :fatalities )");
    batchUpdateSql = "INSERT INTO CONFLICT (".concat("GWNO, ").concat("EVENT_ID_CNTY, ")
            .concat("EVENT_ID_NO_CNTY, ").concat("EVENT_DATE, ").concat("YEAR, ").concat("TIME_PRECISION, ")
            .concat("EVENT_TYPE, ").concat("ACTOR1, ").concat("ALLY_ACTOR_1, ").concat("INTER1, ")
            .concat("ACTOR2, ").concat("ALLY_ACTOR_2, ").concat("INTER2, ").concat("INTERACTION, ")
            .concat("COUNTRY, ").concat("ADMIN1, ").concat("ADMIN2, ").concat("ADMIN3, ").concat("LOCATION, ")
            .concat("LATITUDE, ").concat("LONGITUDE, ").concat("GEO_PRECIS, ").concat("SOURCE, ")
            .concat("NOTES, ")
            .concat("FATALITIES) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )");
}

From source file:com.dai.dao.EscalaoDaoImpl.java

@Override
public void apagarEscalao(Integer id) {
    String sql = "delete from escalao where idEscalao=" + id;
    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    jdbcTemplate.update(sql);//w ww  .j a  va  2 s.c  o  m

}

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

@Override
public List<Member> getDataList() {
    List<Member> memberList = new ArrayList<Member>();

    String sql = "SELECT * FROM member_studio_musik";

    sql = "SELECT * FROM `studiomusik`.`member_studio_musik`";

    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    memberList = jdbcTemplate.query(sql, new MemberRowMapper());
    return memberList;
}

From source file:com.rplt.studioMusik.pegawai.PegawaiDAO.java

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

    String sql = "SELECT * FROM pegawai_studio_musik WHERE username_pegawai = ?";

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

    if (!pegawaiList.isEmpty()) {
        String username = pegawaiList.get(0).getmUsernamePegawai();
        String password = pegawaiList.get(0).getmPaswordPegawai();
        String role = pegawaiList.get(0).getmRolePegawai();
        if (pUsername.equalsIgnoreCase(username) && pPassword.equals(password)) {
            System.out.println("ROLE : " + role);
            if (role.equalsIgnoreCase(ROLE.OPERATOR)) {
                return 2;
            } else if (role.equalsIgnoreCase(ROLE.OWNER)) {
                return 3;
            }/* w w w .jav a 2  s.  c  o m*/
        } else {
            System.out.println("WRONG USERNAME/PASSWORD/ROLE");
            return 1;
        }
    } else {
        System.out.println("UNREGISTERED USERNAME");
        return 0;
    }

    return -1;
}