forked from Inspur_ESG_Bigdata/time-space-web
添加连接oracle数据库功能
This commit is contained in:
parent
a754096b9c
commit
005b2a824d
9
pom.xml
9
pom.xml
|
@ -77,6 +77,13 @@
|
|||
<version>1.2.57</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.oracle</groupId>
|
||||
<artifactId>ojdbc6</artifactId>
|
||||
<version>11.2.0.3</version>
|
||||
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
@ -90,7 +97,9 @@
|
|||
<fork>true</fork>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
</plugins>
|
||||
|
||||
</build>
|
||||
|
||||
</project>
|
||||
|
|
|
@ -102,8 +102,8 @@ public class MainController {
|
|||
private String previewSingleMap(HttpSession httpSession, HttpServletResponse httpServletResponse){
|
||||
MyDataSourceProperty myDataSourceProperty = (MyDataSourceProperty)httpSession.getAttribute("dataSource");
|
||||
TimeSpaceForm timeSpaceForm = (TimeSpaceForm) httpSession.getAttribute("timeSpaceForm");
|
||||
// String name = timeSpaceForm.getUniqueName();
|
||||
String name = "李白";
|
||||
String name = timeSpaceForm.getUniqueName();
|
||||
//String name = "李白";
|
||||
System.out.println(myDataSourceProperty.toString());
|
||||
System.out.println(timeSpaceForm.getUniqueName());
|
||||
List<PeopleOrientation> peopleOrientations = TimeSpaceService.getPeopleOrientations(myDataSourceProperty);
|
||||
|
|
|
@ -12,23 +12,15 @@ public class MyDataSourceProperty {
|
|||
private String tableName;
|
||||
private String userName;
|
||||
private String password;
|
||||
private String driverClass;
|
||||
|
||||
public MyDataSourceProperty(String dataSourceUrl, String tableName, String userName, String password) {
|
||||
this.dataSourceUrl = dataSourceUrl;
|
||||
this.tableName = tableName;
|
||||
this.userName = userName;
|
||||
this.password = password;
|
||||
this.driverClass = DriverClassUtil.MySQL.getDriverClass();
|
||||
this.dataSourceUrl = dataSourceUrl.trim();
|
||||
this.tableName = tableName.trim();
|
||||
this.userName = userName.trim();
|
||||
this.password = password.trim();
|
||||
}
|
||||
|
||||
public String getDriverClass() {
|
||||
return driverClass;
|
||||
}
|
||||
|
||||
public void setDriverClass(String driverClass) {
|
||||
this.driverClass = driverClass;
|
||||
}
|
||||
|
||||
public MyDataSourceProperty() {
|
||||
}
|
||||
|
|
|
@ -28,7 +28,14 @@ public class MainService {
|
|||
DataSource dataSource = DataSourceUtil.createDataSource(myDataSourceProperty);
|
||||
Connection connection = dataSource.getConnection();
|
||||
Statement statement = connection.createStatement();
|
||||
ResultSet resultSet = statement.executeQuery("SELECT * FROM " + myDataSourceProperty.getTableName()+" limit 10");
|
||||
ResultSet resultSet = null;
|
||||
if(myDataSourceProperty.getDataSourceUrl().contains("oracle")||myDataSourceProperty.getDataSourceUrl().contains("ORACLE")) {
|
||||
resultSet = statement.executeQuery("SELECT * FROM " + "\"" + myDataSourceProperty.getTableName() + "\"" + " where rownum<=10");
|
||||
}
|
||||
|
||||
else
|
||||
resultSet = statement.executeQuery("SELECT * FROM " +myDataSourceProperty.getTableName()+" limit 10");
|
||||
|
||||
ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
|
||||
int count = resultSetMetaData.getColumnCount();
|
||||
previewData = new PreviewData();
|
||||
|
@ -59,11 +66,15 @@ public class MainService {
|
|||
public List<Object> getUniqueName(MyDataSourceProperty myDataSourceProperty, TimeSpaceForm timeSpaceForm){
|
||||
PreviewData previewData;
|
||||
List<Object> res = new ArrayList<>();
|
||||
Connection connection = null;
|
||||
Statement statement = null;
|
||||
try {
|
||||
DataSource dataSource = DataSourceUtil.createDataSource(myDataSourceProperty);
|
||||
Connection connection = dataSource.getConnection();
|
||||
Statement statement = connection.createStatement();
|
||||
connection = dataSource.getConnection();
|
||||
statement = connection.createStatement();
|
||||
String sqlFormat = "SELECT DISTINCT %s FROM %s";
|
||||
if(myDataSourceProperty.getDataSourceUrl().contains("oracle")||myDataSourceProperty.getDataSourceUrl().contains("ORACLE"))
|
||||
sqlFormat = "SELECT DISTINCT \"%s\" FROM \"%s\"";
|
||||
String sql = String.format(sqlFormat,timeSpaceForm.getNameColumn(),myDataSourceProperty.getTableName());
|
||||
ResultSet resultSet = statement.executeQuery(sql);
|
||||
ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
|
||||
|
@ -71,13 +82,21 @@ public class MainService {
|
|||
while (resultSet.next()) {
|
||||
res.add(resultSet.getObject(1));
|
||||
}
|
||||
statement.close();
|
||||
connection.close();
|
||||
|
||||
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
return res;
|
||||
}finally {
|
||||
try {
|
||||
if(statement!=null)
|
||||
statement.close();
|
||||
if(connection !=null)
|
||||
connection.close();
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
return res;
|
||||
|
@ -85,11 +104,15 @@ public class MainService {
|
|||
|
||||
public PreviewData previewSingle(MyDataSourceProperty myDataSourceProperty, TimeSpaceForm timeSpaceForm){
|
||||
PreviewData previewData;
|
||||
Connection connection =null;
|
||||
Statement statement = null;
|
||||
try {
|
||||
DataSource dataSource = DataSourceUtil.createDataSource(myDataSourceProperty);
|
||||
Connection connection = dataSource.getConnection();
|
||||
Statement statement = connection.createStatement();
|
||||
connection = dataSource.getConnection();
|
||||
statement = connection.createStatement();
|
||||
String sqlFormat = "SELECT %s,%s,%s FROM %s WHERE %s='%s' ORDER BY %s LIMIT 10";
|
||||
if(myDataSourceProperty.getDataSourceUrl().contains("oracle")||myDataSourceProperty.getDataSourceUrl().contains("ORACLE"))
|
||||
sqlFormat = "SELECT \"%s\",\"%s\",\"%s\" FROM \"%s\" WHERE \"%s\"='%s' AND rownum<=10 ORDER BY \"%s\"";
|
||||
String sql = String.format(sqlFormat,timeSpaceForm.getNameColumn(),timeSpaceForm.getTimeColumn(),timeSpaceForm.getSpaceColumn(),myDataSourceProperty.getTableName(),timeSpaceForm.getNameColumn(),timeSpaceForm.getUniqueName(),timeSpaceForm.getTimeColumn());
|
||||
System.out.println(sql);
|
||||
ResultSet resultSet = statement.executeQuery(sql);
|
||||
|
@ -115,7 +138,14 @@ public class MainService {
|
|||
e.printStackTrace();
|
||||
return null;
|
||||
}finally {
|
||||
|
||||
try {
|
||||
if(statement!=null)
|
||||
statement.close();
|
||||
if(connection !=null)
|
||||
connection.close();
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return previewData;
|
||||
}
|
||||
|
|
|
@ -43,6 +43,8 @@ public class MysqlUtil {
|
|||
}catch (SQLException ex){
|
||||
ex.printStackTrace();
|
||||
return null;
|
||||
}finally {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,10 +29,16 @@ public class TimeSpaceService {
|
|||
}
|
||||
|
||||
public static List<PeopleOrientation> getPeopleOrientations(MyDataSourceProperty myDataSourceProperty){
|
||||
Connection conn = null;
|
||||
Statement statement = null;
|
||||
try {
|
||||
Connection conn = MysqlUtil.getConnection(myDataSourceProperty);
|
||||
Statement statement = conn.createStatement();
|
||||
ResultSet resultSet = statement.executeQuery("SELECT * FROM " + myDataSourceProperty.getTableName());
|
||||
conn = MysqlUtil.getConnection(myDataSourceProperty);
|
||||
statement = conn.createStatement();
|
||||
ResultSet resultSet = null;
|
||||
if(myDataSourceProperty.getDataSourceUrl().contains("oracle")||myDataSourceProperty.getDataSourceUrl().contains("ORACLE"))
|
||||
resultSet = statement.executeQuery("SELECT * FROM " + "\""+myDataSourceProperty.getTableName()+ "\"");
|
||||
else
|
||||
resultSet = statement.executeQuery("SELECT * FROM " +myDataSourceProperty.getTableName());
|
||||
Map<String, List<Orientation> > hashMapPeopleOrientations = new HashMap<>();
|
||||
while (resultSet.next()) {
|
||||
String name = resultSet.getString(2);
|
||||
|
@ -49,12 +55,20 @@ public class TimeSpaceService {
|
|||
peopleOrientation.setOrientations(hashMapPeopleOrientations.get(name));
|
||||
peopleOrientations.add(peopleOrientation);
|
||||
}
|
||||
statement.close();
|
||||
conn.close();
|
||||
|
||||
return peopleOrientations;
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}finally {
|
||||
try {
|
||||
if(statement!=null)
|
||||
statement.close();
|
||||
if(conn !=null)
|
||||
conn.close();
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,9 +14,13 @@ public class DataSourceUtil {
|
|||
|
||||
public static DataSource createDataSource (MyDataSourceProperty myDataSourceProperty)throws Exception{
|
||||
DriverManagerDataSource dataSource = new DriverManagerDataSource();
|
||||
if(myDataSourceProperty.getDataSourceUrl().contains("mysql"))
|
||||
dataSource.setUrl(myDataSourceProperty.getDataSourceUrl()+"?useUnicode=true&characterEncoding=UTF-8");
|
||||
else
|
||||
dataSource.setUrl(myDataSourceProperty.getDataSourceUrl());
|
||||
dataSource.setUsername(myDataSourceProperty.getUserName());
|
||||
dataSource.setPassword(myDataSourceProperty.getPassword());
|
||||
|
||||
return dataSource;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
server.port=8080
|
||||
server.port=8088
|
||||
|
||||
spring.thymeleaf.cache=false
|
||||
|
||||
|
|
Binary file not shown.
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.oracle</groupId>
|
||||
<artifactId>ojdbc6</artifactId>
|
||||
<version>11.2.0.3</version>
|
||||
<description>Artifactory auto generated POM</description>
|
||||
</project>
|
|
@ -3,7 +3,7 @@
|
|||
<head>
|
||||
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<title>Hello, World</title>
|
||||
<title>Track Presentation</title>
|
||||
<style type="text/css">
|
||||
html{height:100%}
|
||||
body{height:100%;margin:0px;padding:0px}
|
||||
|
|
Loading…
Reference in New Issue