class.4name

This commit is contained in:
insanity 2017-05-18 13:27:27 +09:00
parent fc501e6c7f
commit 93d05aaa41
2 changed files with 6 additions and 11 deletions

View File

@ -12,7 +12,7 @@
<groupId>com.loafle.overflow</groupId>
<artifactId>crawler_sql</artifactId>
<version>1.0.6-SNAPSHOT</version>
<version>1.0.0-SNAPSHOT</version>
<dependencies>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->

View File

@ -19,12 +19,11 @@ public class SQLCrawler extends Crawler {
public SQLCrawler() {}
@Override
public Object getInternal(Config config) {
public Object getInternal(Config config) throws Exception {
return getMetrics(config);
}
private Object getMetrics(Config config) {
private Object getMetrics(Config config) throws Exception {
Connection conn = null;
Statement stmt = null;
@ -37,13 +36,13 @@ public class SQLCrawler extends Crawler {
try {
if (url.contains("mysql")) {
Class.forName("com.mysql.jdbc.Driver");
}else if (url.contains("pgsql")) {
}else if (url.contains("postgresql")) {
Class.forName("org.postgresql.Driver");
}else if (url.contains("sqlserver")) {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
}
}catch(Exception e) {
e.printStackTrace();
}
List<OFResultSet> resultSets = new ArrayList<>();
@ -72,14 +71,10 @@ public class SQLCrawler extends Crawler {
resultSets.add(resultSet);
rs.close();
}
if (resultSets.size() <= 0) {
return new Exception("No data found.");
}
return resultSets;
} catch (Exception e) {
e.printStackTrace();
return e;
throw e;
} finally {
if (conn != null) {try {conn.close();} catch (SQLException e) {e.printStackTrace();}}
if (rs != null) {try {rs.close();} catch (SQLException e) {e.printStackTrace();}}