diff --git a/pom.xml b/pom.xml index ccfa759..61c1d5f 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ com.loafle.overflow crawler_sql - 1.0.0-SNAPSHOT + 1.0.6-SNAPSHOT diff --git a/src/main/java/com/loafle/overflow/crawler/sql/SQLCrawler.java b/src/main/java/com/loafle/overflow/crawler/sql/SQLCrawler.java index 4ee8127..a2db85b 100644 --- a/src/main/java/com/loafle/overflow/crawler/sql/SQLCrawler.java +++ b/src/main/java/com/loafle/overflow/crawler/sql/SQLCrawler.java @@ -34,6 +34,18 @@ public class SQLCrawler extends Crawler { String id = (String)config.getTarget().getAuth().get("id"); String pw = (String)config.getTarget().getAuth().get("pw"); + try { + if (url.contains("mysql")) { + Class.forName("com.mysql.jdbc.Driver"); + }else if (url.contains("pgsql")) { + Class.forName("org.postgresql.Driver"); + }else if (url.contains("sqlserver")) { + Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); + } + }catch(Exception e) { + + } + List resultSets = new ArrayList<>(); try { @@ -60,17 +72,19 @@ 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(); - new Exception(e.getMessage()).printStackTrace(); + return e; } finally { if (conn != null) {try {conn.close();} catch (SQLException e) {e.printStackTrace();}} if (rs != null) {try {rs.close();} catch (SQLException e) {e.printStackTrace();}} if (stmt != null) {try {stmt.close();} catch (SQLException e) {e.printStackTrace();}} } - return null; } }