Skip to content

Commit 5df04af

Browse files
committed
Revert "Remove SpringBootApp"
This reverts commit 9bc6f62.
1 parent 9bc6f62 commit 5df04af

File tree

5 files changed

+175
-0
lines changed

5 files changed

+175
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import java.util.List;
2+
3+
import javax.sql.DataSource;
4+
5+
import org.springframework.jdbc.core.JdbcTemplate;
6+
7+
/**
8+
* Simple Java class which uses Spring's JdbcTemplate class to implement
9+
* business logic.
10+
*
11+
*/
12+
public class EmpJDBCTemplate {
13+
private DataSource dataSource;
14+
private JdbcTemplate jdbcTemplate;
15+
16+
public void setDataSource(DataSource dataSource) {
17+
this.dataSource = dataSource;
18+
this.jdbcTemplate = new JdbcTemplate(dataSource);
19+
20+
}
21+
22+
public void displayEmpList() {
23+
final String sql = "SELECT empno, ename, job, mgr, sal, deptno FROM emp";
24+
List<EmployeeDAO> employees = jdbcTemplate.query(sql, new EmployeeMapper());
25+
26+
System.out.println(
27+
String.format("%20s %20s %20s %20s %20s %20s \n", "EMPNO", "ENAME", "JOB", "MGR", "SALARY", "DEPT"));
28+
29+
30+
for (EmployeeDAO employee : employees) {
31+
System.out.println(String.format("%20d %20s %20s %20d %20d %20d", employee.getEmpno(), employee.getName(),
32+
employee.getJob(), employee.getMgr(), employee.getSal(), employee.getDeptno()));
33+
}
34+
}
35+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
2+
/**
3+
* Simple DAO class implementation for EMP table.
4+
*
5+
*/
6+
public class EmployeeDAO {
7+
private int empno;
8+
private String name;
9+
private String job;
10+
private int mgr;
11+
private int sal;
12+
private int deptno;
13+
14+
public int getEmpno() {
15+
return empno;
16+
}
17+
18+
public void setEmpno(int empno) {
19+
this.empno = empno;
20+
}
21+
22+
public String getName() {
23+
return name;
24+
}
25+
26+
public void setName(String name) {
27+
this.name = name;
28+
}
29+
30+
public String getJob() {
31+
return job;
32+
}
33+
34+
public void setJob(String job) {
35+
this.job = job;
36+
}
37+
38+
public int getMgr() {
39+
return mgr;
40+
}
41+
42+
public void setMgr(int mgr) {
43+
this.mgr = mgr;
44+
}
45+
46+
public int getSal() {
47+
return sal;
48+
}
49+
50+
public void setSal(int sal) {
51+
this.sal = sal;
52+
}
53+
54+
public int getDeptno() {
55+
return deptno;
56+
}
57+
58+
public void setDeptno(int deptno) {
59+
this.deptno = deptno;
60+
}
61+
62+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import java.sql.ResultSet;
2+
import java.sql.SQLException;
3+
4+
import org.springframework.jdbc.core.RowMapper;
5+
6+
/**
7+
* Simple Row mapper implementation class for EMP table.
8+
*
9+
*/
10+
public class EmployeeMapper implements RowMapper<EmployeeDAO> {
11+
12+
@Override
13+
public EmployeeDAO mapRow(ResultSet rs, int rowNo) throws SQLException {
14+
EmployeeDAO emp = new EmployeeDAO();
15+
emp.setEmpno(rs.getInt("empno"));
16+
emp.setName(rs.getString("ename"));
17+
emp.setJob(rs.getString("job"));
18+
emp.setMgr(rs.getInt("mgr"));
19+
emp.setSal(rs.getInt("sal"));
20+
emp.setDeptno(rs.getInt("deptno"));
21+
22+
return emp;
23+
}
24+
25+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beans xmlns="http://www.springframework.org/schema/beans"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
5+
6+
<!-- Initialization for data source -->
7+
<bean id="dataSource" class="oracle.ucp.jdbc.PoolDataSourceImpl">
8+
<property name="connectionFactoryClassName"
9+
value="oracle.jdbc.pool.OracleDataSource" />
10+
<!-- Connection URL uses a TNS alias -->
11+
<property name="URL" value="jdbc:oracle:thin:@jdbctest_medium?TNS_ADMIN=D:/temp/wallet_JDBCTEST" />
12+
<property name="user" value="testuser" />
13+
<property name="password" value="password!234!" />
14+
<property name="maxPoolSize" value="10" />
15+
<property name="initialPoolSize" value="5" />
16+
</bean>
17+
18+
<!-- Definition for EmpJDBCTemplate bean -->
19+
<bean id="EmpJDBCTemplate" class="EmpJDBCTemplate">
20+
<property name="dataSource" ref="dataSource" />
21+
</bean>
22+
23+
</beans>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
import org.springframework.boot.CommandLineRunner;
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.context.ApplicationContext;
5+
import org.springframework.context.annotation.Bean;
6+
import org.springframework.context.annotation.ImportResource;
7+
8+
/**
9+
* SpringBoot application main class. It uses JdbcTemplate class which
10+
* internally uses UCP for connection check-outs and check-ins.
11+
*
12+
*/
13+
// Specify the Spring XML config file name
14+
@ImportResource({ "classpath*:HelloAppConfig.xml" })
15+
public class HelloApplication {
16+
17+
public static void main(String[] args) {
18+
SpringApplication.run(HelloApplication.class, args);
19+
}
20+
21+
@Bean
22+
public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
23+
return args -> {
24+
final EmpJDBCTemplate empJDBCTemplate = (EmpJDBCTemplate) ctx.getBean("EmpJDBCTemplate");
25+
System.out.println("Listing employee records : ");
26+
empJDBCTemplate.displayEmpList();
27+
};
28+
}
29+
30+
}

0 commit comments

Comments
 (0)