-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClones.java
45 lines (39 loc) · 1.28 KB
/
Clones.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package database;
import java.io.IOException;
import java.nio.file.Path;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Clones {
public static long numClones(long id) throws SQLException {
long retval = 0;
String sql = "SELECT count(1) FROM tool_" + id + "_clones";
Connection conn = ToolsDB.getConnection();
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
if(rs.next())
retval = rs.getLong(1);
stmt.close();
conn.close();
return retval;
}
public static int clearClones(long id) throws SQLException {
Connection conn = ToolsDB.getConnection();
String sql = "DELETE FROM tool_" + id + "_clones";
Statement stmt = conn.createStatement();
int retval = stmt.executeUpdate(sql);
stmt.close();
conn.close();
return retval;
}
public static long importClones(long id, Path path) throws IOException, SQLException {
// Import
Connection conn = ToolsDB.getConnection();
String sql = "INSERT INTO tool_" + id + "_clones SELECT * FROM csvread('" + path.toString() + "','type1,name1,startline1,endline1,type2,name2,startline2,endline2')";
Statement stmt = conn.createStatement();
long retval = stmt.executeUpdate(sql);
conn.close();
return retval;
}
}