class.4name
This commit is contained in:
parent
6fbd452013
commit
fc501e6c7f
2
pom.xml
2
pom.xml
|
@ -12,7 +12,7 @@
|
|||
|
||||
<groupId>com.loafle.overflow</groupId>
|
||||
<artifactId>crawler_sql</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<version>1.0.6-SNAPSHOT</version>
|
||||
|
||||
<dependencies>
|
||||
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-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<OFResultSet> 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user