From bc90de3c16e5e96ba4bcb5d84df5016c968fa4ec Mon Sep 17 00:00:00 2001 From: zack Date: Tue, 27 Apr 2021 17:06:02 +0800 Subject: [PATCH 1/2] =?UTF-8?q?REPORT-50963=20=E6=96=B0demo=E9=87=8C?= =?UTF-8?q?=E9=9D=A2=E8=8E=B7=E5=8F=96=E8=BF=9E=E6=8E=A5=E7=9A=84=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E8=B7=9F=E8=80=81demo=E4=B8=80=E8=87=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fr/data/SimpleParamTableDataDemo.java | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/fr/data/SimpleParamTableDataDemo.java b/src/main/java/com/fr/data/SimpleParamTableDataDemo.java index dc1b7fd..b7ef716 100644 --- a/src/main/java/com/fr/data/SimpleParamTableDataDemo.java +++ b/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 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; + } } \ No newline at end of file From 471a43570cb34d7855e8c208617dd52141fb3bc5 Mon Sep 17 00:00:00 2001 From: zack Date: Tue, 27 Apr 2021 17:09:10 +0800 Subject: [PATCH 2/2] rt --- src/main/java/com/fr/data/ParamTableDataDemo.java | 6 +++--- src/main/java/com/fr/data/SimpleParamTableDataDemo.java | 5 ++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/fr/data/ParamTableDataDemo.java b/src/main/java/com/fr/data/ParamTableDataDemo.java index b5c2cd8..2d7f562 100644 --- a/src/main/java/com/fr/data/ParamTableDataDemo.java +++ b/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; } diff --git a/src/main/java/com/fr/data/SimpleParamTableDataDemo.java b/src/main/java/com/fr/data/SimpleParamTableDataDemo.java index b7ef716..0bb630e 100644 --- a/src/main/java/com/fr/data/SimpleParamTableDataDemo.java +++ b/src/main/java/com/fr/data/SimpleParamTableDataDemo.java @@ -83,14 +83,13 @@ public class SimpleParamTableDataDemo extends SimpleTableData { 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; }