Browse Source

Pull request #47: REPORT-50963 新demo里面获取连接的逻辑跟老demo一致

Merge in PG/plugin-report-doc-demo from ~ZACK/plugin-report-doc-demo:release/10.0 to release/10.0

* commit '471a43570cb34d7855e8c208617dd52141fb3bc5':
  rt
  REPORT-50963 新demo里面获取连接的逻辑跟老demo一致
release/10.0
zack 4 years ago
parent
commit
0cf74b4e96
  1. 6
      src/main/java/com/fr/data/ParamTableDataDemo.java
  2. 27
      src/main/java/com/fr/data/SimpleParamTableDataDemo.java

6
src/main/java/com/fr/data/ParamTableDataDemo.java

@ -2,6 +2,7 @@ package com.fr.data;
import com.fr.base.FRContext;
import com.fr.file.DatasourceManager;
import com.fr.log.FineLoggerFactory;
import com.fr.stable.ParameterProvider;
import java.sql.Connection;
import java.sql.DriverManager;
@ -133,14 +134,13 @@ public class ParamTableDataDemo extends AbstractTableData {
String url = "jdbc:sqlite:////Applications//FineReport10_325//webapps//webroot//help//FRDemo.db";
String username = "";
String password = "";
Connection con;
Connection con = null;
try {
Class.forName(driverName);
con = DriverManager.getConnection(url, username, password);
} catch (Exception e) {
e.printStackTrace();
return null;
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
return con;
}

27
src/main/java/com/fr/data/SimpleParamTableDataDemo.java

@ -1,10 +1,10 @@
package com.fr.data;
import com.fr.file.DatasourceManager;
import com.fr.log.FineLoggerFactory;
import com.fr.stable.ParameterProvider;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
@ -38,11 +38,9 @@ public class SimpleParamTableDataDemo extends SimpleTableData {
FineLoggerFactory.getLogger().info("Query SQL of ParamTableDataDemo: \n" + sql);
// 保存得到的结果集
ArrayList<Object[]> valueList = new ArrayList();
// 下面开始建立数据库连接,按照刚才的SQL语句进行查询
com.fr.data.impl.Connection conn = DatasourceManager.getInstance().getConnection("FRDemo");
Connection con = null;
try {
con = conn.createConnection();
con = getConnection();
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(sql);
// 获得记录的详细信息,然后获得总列数
@ -74,4 +72,25 @@ public class SimpleParamTableDataDemo extends SimpleTableData {
}
return valueList;
}
/**
* 获取数据库连接 driverName和 url 可以换成您需要的
*
* @return Connection
*/
private Connection getConnection() {
String driverName = "org.sqlite.JDBC";
String url = "jdbc:sqlite:////Applications//FineReport10_325//webapps//webroot//help//FRDemo.db";
String username = "";
String password = "";
Connection con = null;
try {
Class.forName(driverName);
con = DriverManager.getConnection(url, username, password);
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
return con;
}
}
Loading…
Cancel
Save