JdbcUtils1:
import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidDataSourceFactory;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;
public class JdbcUtils1 {
private static DruidDataSource dataSource;
static {
Properties properties = new Properties();
InputStream resourceAsStream = JdbcUtils.class.getClassLoader().getResourceAsStream("jdbc1.properties");
try {
properties.load(resourceAsStream);
try {
dataSource = (DruidDataSource) DruidDataSourceFactory.createDataSource(properties);
} catch (Exception e) {
e.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();
}
}
public static Connection getConnection() {
Connection conn = null;
try {
conn = dataSource.getConnection();
} catch (SQLException throwable) {
throwable.printStackTrace();
}
return conn;
}
public static void close(Connection conn) {
if (conn != null) {
try {
conn.close();
} catch (SQLException throwable) {
throwable.printStackTrace();
}
}
}
}
Connection connection = null;
connection = JdbcUtils1.getConnection();
List<DmdzDto> dmdzDtos = new ArrayList<>();
List<AddressResultDto> addressResultDtos = new ArrayList<>();
Map<String, Object> resMap = new HashMap<>();
String sqls = "select * from test";
try {
PreparedStatement preparedStatement = connection.prepareStatement(sqls);
boolean execute = preparedStatement.execute();
while (execute){
ResultSet resultSet = preparedStatement.getResultSet();
while (resultSet.next()) {
String X = resultSet.getString("X");
}
}
execute = preparedStatement.getMoreResults();
}
preparedStatement.close();
} catch (SQLException throwables) {
throwables.printStackTrace();
} finally {
JdbcUtils1.close(connection);
}
username=test
password=test
url=jdbc:oracle:thin:@127.0.0.1:1521:helowin
driverClassName=oracle.jdbc.driver.OracleDriver
initialSize=5
maxActive=20
pom文件添加依赖
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.3</version>
</dependency>