Browse Source

REPORT-50963 新demo里面获取连接的逻辑跟老demo一致

release/11.0
zack 4 years ago
parent
commit
bc90de3c16
  1. 28
      src/main/java/com/fr/data/SimpleParamTableDataDemo.java

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

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