Search in sources :

Example 31 with DriverManagerDataSource

use of org.springframework.jdbc.datasource.DriverManagerDataSource in project SpringStepByStep by JavaProgrammerLB.

the class DatabaseConfig method dataSource.

@Bean
public DataSource dataSource() {
    DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setDriverClassName("com.mysql.jdbc.Driver");
    dataSource.setUrl("jdbc:mysql://localhost:3306/myminitwit");
    dataSource.setUsername("root");
    dataSource.setPassword("root");
    return dataSource;
}
Also used : DriverManagerDataSource(org.springframework.jdbc.datasource.DriverManagerDataSource) Bean(org.springframework.context.annotation.Bean)

Example 32 with DriverManagerDataSource

use of org.springframework.jdbc.datasource.DriverManagerDataSource in project spring-framework by spring-projects.

the class RdbmsOperationTests method setTypeAfterCompile.

@Test
public void setTypeAfterCompile() {
    operation.setDataSource(new DriverManagerDataSource());
    operation.setSql("select * from mytable");
    operation.compile();
    assertThatExceptionOfType(InvalidDataAccessApiUsageException.class).isThrownBy(() -> operation.setTypes(new int[] { Types.INTEGER }));
}
Also used : DriverManagerDataSource(org.springframework.jdbc.datasource.DriverManagerDataSource) InvalidDataAccessApiUsageException(org.springframework.dao.InvalidDataAccessApiUsageException) Test(org.junit.jupiter.api.Test)

Example 33 with DriverManagerDataSource

use of org.springframework.jdbc.datasource.DriverManagerDataSource in project spring-framework by spring-projects.

the class RdbmsOperationTests method validateInOutParameter.

@Test
public void validateInOutParameter() {
    operation.setDataSource(new DriverManagerDataSource());
    operation.setSql("DUMMY_PROC");
    operation.declareParameter(new SqlOutParameter("DUMMY_OUT_PARAM", Types.VARCHAR));
    operation.declareParameter(new SqlInOutParameter("DUMMY_IN_OUT_PARAM", Types.VARCHAR));
    operation.validateParameters(new Object[] { "DUMMY_VALUE1", "DUMMY_VALUE2" });
}
Also used : DriverManagerDataSource(org.springframework.jdbc.datasource.DriverManagerDataSource) SqlOutParameter(org.springframework.jdbc.core.SqlOutParameter) SqlInOutParameter(org.springframework.jdbc.core.SqlInOutParameter) Test(org.junit.jupiter.api.Test)

Example 34 with DriverManagerDataSource

use of org.springframework.jdbc.datasource.DriverManagerDataSource in project spring-framework by spring-projects.

the class RdbmsOperationTests method parametersSetWithList.

@Test
public void parametersSetWithList() {
    DataSource ds = new DriverManagerDataSource();
    operation.setDataSource(ds);
    operation.setSql("select * from mytable where one = ? and two = ?");
    operation.setParameters(new SqlParameter[] { new SqlParameter("one", Types.NUMERIC), new SqlParameter("two", Types.NUMERIC) });
    operation.afterPropertiesSet();
    operation.validateParameters(new Object[] { 1, "2" });
    assertThat(operation.getDeclaredParameters().size()).isEqualTo(2);
}
Also used : SqlParameter(org.springframework.jdbc.core.SqlParameter) DriverManagerDataSource(org.springframework.jdbc.datasource.DriverManagerDataSource) DataSource(javax.sql.DataSource) DriverManagerDataSource(org.springframework.jdbc.datasource.DriverManagerDataSource) Test(org.junit.jupiter.api.Test)

Example 35 with DriverManagerDataSource

use of org.springframework.jdbc.datasource.DriverManagerDataSource in project spring-framework by spring-projects.

the class RdbmsOperationTests method compileTwice.

@Test
public void compileTwice() {
    operation.setDataSource(new DriverManagerDataSource());
    operation.setSql("select * from mytable");
    operation.setTypes(null);
    operation.compile();
    operation.compile();
}
Also used : DriverManagerDataSource(org.springframework.jdbc.datasource.DriverManagerDataSource) Test(org.junit.jupiter.api.Test)

Aggregations

DriverManagerDataSource (org.springframework.jdbc.datasource.DriverManagerDataSource)66 Bean (org.springframework.context.annotation.Bean)29 LocalContainerEntityManagerFactoryBean (org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean)20 Test (org.junit.jupiter.api.Test)9 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)8 DataSource (javax.sql.DataSource)7 SQLException (java.sql.SQLException)4 Properties (java.util.Properties)4 PersistenceUnitInfo (jakarta.persistence.spi.PersistenceUnitInfo)2 FileInputStream (java.io.FileInputStream)2 IOException (java.io.IOException)2 Connection (java.sql.Connection)2 ArrayList (java.util.ArrayList)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 InitialContext (javax.naming.InitialContext)2 XADataSource (javax.sql.XADataSource)2 Before (org.junit.Before)2 ApplicationContextHolder (org.mifos.application.servicefacade.ApplicationContextHolder)2 ServletRegistrationBean (org.springframework.boot.web.servlet.ServletRegistrationBean)2