|
|
|
@ -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,26 @@ 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; |
|
|
|
|
try { |
|
|
|
|
Class.forName(driverName); |
|
|
|
|
con = DriverManager.getConnection(url, username, password); |
|
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
return con; |
|
|
|
|
} |
|
|
|
|
} |