class.4name

This commit is contained in:
insanity 2017-05-18 12:02:00 +09:00
parent 6fbd452013
commit fc501e6c7f
2 changed files with 17 additions and 3 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.0-SNAPSHOT</version> <version>1.0.6-SNAPSHOT</version>
<dependencies> <dependencies>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java --> <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->

View File

@ -34,6 +34,18 @@ public class SQLCrawler extends Crawler {
String id = (String)config.getTarget().getAuth().get("id"); String id = (String)config.getTarget().getAuth().get("id");
String pw = (String)config.getTarget().getAuth().get("pw"); 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<OFResultSet> resultSets = new ArrayList<>(); List<OFResultSet> resultSets = new ArrayList<>();
try { try {
@ -60,17 +72,19 @@ 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(); e.printStackTrace();
new Exception(e.getMessage()).printStackTrace(); 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();}}
if (stmt != null) {try {stmt.close();} catch (SQLException e) {e.printStackTrace();}} if (stmt != null) {try {stmt.close();} catch (SQLException e) {e.printStackTrace();}}
} }
return null;
} }
} }