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> <groupId>com.loafle.overflow</groupId>
<artifactId>crawler_sql</artifactId> <artifactId>crawler_sql</artifactId>
<version>1.0.6-SNAPSHOT</version> <version>1.0.0-SNAPSHOT</version>
<dependencies> <dependencies>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java --> <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->

View File

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