List of usage examples for org.springframework.jdbc.core JdbcTemplate JdbcTemplate
public JdbcTemplate(DataSource dataSource)
From source file:User_Manager.User_TblJDBCTemplate.java
public User_TblJDBCTemplate() throws SQLException { ApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml"); conn = (connectivity) context.getBean("connectivity"); this.jdbcTemplateObject = new JdbcTemplate(conn.getDataSource()); }
From source file:edu.jhuapl.openessence.web.util.MapQueryUtil.java
public int performNextSequenceValueQuery(String sequenceForMapRequestId) { JdbcTemplate pgdb = new JdbcTemplate(mapDataSource); return pgdb.queryForInt("select nextval(\'" + sequenceForMapRequestId + "\')"); }
From source file:org.jasig.schedassist.impl.InitializeSchedulingAssistantDatabase.java
/** * //w w w . j a v a 2 s . co m * @param dataSource */ public void setDataSource(final DataSource dataSource) { this.jdbcTemplate = new JdbcTemplate(dataSource); }
From source file:just.aRest.project.DAO.ApplDAOImpl.java
@Override public ResponseEntity<String> createApplication(Application app) { JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); String query = "SELECT email FROM Client WHERE username = ? LIMIT 1"; try {//from ww w. j a v a 2s.c o m //before creating the application check if the user exists String checker0 = jdbcTemplate.queryForObject(query, new Object[] { app.getUsername() }, String.class); int checker = 0; if (checker0.equals("") || checker0 == null) checker = 0; else checker = 1; if (checker == 1) { //Create the application query = "INSERT INTO Application VALUES(?,?,?,?,?,?,?,0,0,?,10)"; checker = jdbcTemplate.update(query, app.getApp_code(), app.getAmount(), app.getRepay_Time(), app.getBuy_type(), app.getDrivers_license(), app.getTaxes(), app.getTekmiriwsi(), app.getUsername()); //enter empty field for Directors Commentary if (checker == 1) { query = "INSERT INTO Director VALUES(\"\",?)"; checker = jdbcTemplate.update(query, app.getApp_code()); if (checker == 1) { //Return user for successful completion return new ResponseEntity<String>("Opperation completed successfully", HttpStatus.OK); } else { //inform him that something went wrong return new ResponseEntity<String>("Very rare issue,contact technical support", HttpStatus.NOT_ACCEPTABLE); } } else { return new ResponseEntity<String>("Fill the form correctly", HttpStatus.NOT_ACCEPTABLE); } } else { return new ResponseEntity<String>("User doesn\'t exist", HttpStatus.NOT_ACCEPTABLE); } } catch (EmptyResultDataAccessException e) { return new ResponseEntity<String>("User doesn\'t exist", HttpStatus.NOT_ACCEPTABLE); } catch (NumberFormatException e) { return new ResponseEntity<String>("Form filled incorrectly", HttpStatus.NOT_ACCEPTABLE); } }
From source file:com.company.project.service.dao.PersistentTokenDao.java
public void createTable() { JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); jdbcTemplate.update("create table messages (messagekey varchar(20), message varchar(100))"); }
From source file:org.jtalks.poulpe.util.databasebackup.persistence.DbTableData.java
/** * Constructs a new instance of the class with given DataSource and TableName. These parameters will be used for * preparing table's structure and data. * //ww w .j a v a 2s .c o m * @param dataSource * a DataSource object for accessing the table. * @param tableName * a name of the table to be dumped. */ public DbTableData(DataSource dataSource, String tableName) { Validate.notNull(dataSource, "dataSource parameter must not be null."); Validate.notEmpty(tableName, "tableName parameter must not be empty."); this.dataSource = dataSource; this.tableName = tableName; this.jdbcTemplate = new JdbcTemplate(dataSource); }
From source file:com.talkingdata.orm.tool.ORMGenerateAction.java
@Override public void actionPerformed(AnActionEvent e) { Project project = e.getRequiredData(CommonDataKeys.PROJECT); ORMConfig config = ORMConfig.getInstance(project); // 1. validate input parameter if (!validateConfig(project, config)) { return;//w w w.ja v a 2 s. c om } BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName("com.mysql.jdbc.Driver"); dataSource.setUrl( String.format("jdbc:mysql://%s:%s/%s", config.getIp(), config.getPort(), config.getDatabase())); dataSource.setUsername(config.getUser()); dataSource.setPassword(config.getPassword()); JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); // 2. validate database is connected try { jdbcTemplate.execute("SELECT 1"); } catch (Exception exception) { Messages.showWarningDialog(project, "The database is not connected.", "Warning"); return; } File resourceDirectory = new File(project.getBasePath(), "/src/main/resources/mybatis"); if (!resourceDirectory.exists()) { resourceDirectory.mkdirs(); } File packageDirectory = new File(project.getBasePath(), "/src/main/java/" + config.getPackageName().replaceAll("\\.", "/")); if (!packageDirectory.exists()) { packageDirectory.mkdirs(); } Properties p = new Properties(); p.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, "org.apache.velocity.runtime.log.Log4JLogChute"); Velocity.init(p); // 3. query all table SqlParser sqlParser = new SqlParser(); try { for (ClassDefinition cls : sqlParser.getTables(jdbcTemplate, config.getDatabase(), config.getPackageName())) { Map<String, Object> map = new HashMap<>(1); map.put("cls", cls); File domainDirectory = new File(packageDirectory, "domain"); if (!domainDirectory.exists()) { domainDirectory.mkdirs(); } File clsFile = new File(domainDirectory, cls.getClassName() + ".java"); if (!clsFile.exists()) { clsFile.createNewFile(); } writeFile("com/talkingdata/orm/tool/vm/class.vm", map, new FileWriter(clsFile)); File daoDirectory = new File(packageDirectory, "dao"); if (!daoDirectory.exists()) { daoDirectory.mkdirs(); } File daoFile = new File(daoDirectory, cls.getClassName() + "Dao.java"); if (!daoFile.exists()) { daoFile.createNewFile(); } writeFile("com/talkingdata/orm/tool/vm/dao.vm", map, new FileWriter(daoFile)); File mapperFile = new File(resourceDirectory, cls.getClassInstanceName() + ".xml"); if (!mapperFile.exists()) { mapperFile.createNewFile(); } writeFile("com/talkingdata/orm/tool/vm/mapper.vm", map, new FileWriter(mapperFile)); } } catch (Exception ex) { throw new RuntimeException(ex); } }
From source file:org.epiphanic.instrumentation.performance.AOPMetricGathererIntegrationTest.java
/** * Runs any set up for our unit tests. In this case we create a {@link org.springframework.jdbc.core.JdbcTemplate} for * testing our database state later./*w w w .jav a 2s . c o m*/ */ @Before public void setUp() throws Exception { _jdbcTemplate = new JdbcTemplate(_dataSource); }
From source file:com.pontecultural.flashcards.JdbcFlashcardsDao.java
public int insert(final Deck aDeck) { int rc = -1;// www . ja v a2 s.com String sql = "INSERT INTO decks (name, description) VALUES (?,?)"; JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); jdbcTemplate.update(sql, new PreparedStatementSetter() { public void setValues(PreparedStatement ps) throws SQLException { int index = 1; ps.setString(index, aDeck.getName()); index++; ps.setString(index, aDeck.getDescription()); } }); // There are database specific ways to retrieve the id // for the last inserted row(e.g., last_insert_id() in // mysql. Using MAX(id) because I want to be able to use // different data sources. See Stackoverflow for limitations // on this approach. // http://stackoverflow.com/questions/4734589/retrieve-inserted-row-id-in-sql/4734672 rc = jdbcTemplate.queryForInt("SELECT MAX(_id) from decks"); return rc; }
From source file:de.hybris.platform.flexiblesearch.performance.LimitStatementRawJDBCPerformanceTest.java
@Before public void setUp() throws Exception { createCoreData();//w w w . j a va 2 s .com stopWatch = new Stopwatch(); jdbcTemplate = new JdbcTemplate(Registry.getCurrentTenantNoFallback().getDataSource()); createTestObjects(10000); }