source: trunk/CrossPare/src/de/ugoe/cs/cpdp/eval/MySQLResultStorage.java @ 68

Last change on this file since 68 was 68, checked in by sherbold, 8 years ago
  • added the concept of result storages to the framework and implemented a very simple first prototype of a MySQLResultStorage (that currently only works with a locally running database)
  • Property svn:mime-type set to text/plain
File size: 3.4 KB
Line 
1
2package de.ugoe.cs.cpdp.eval;
3
4import java.sql.Connection;
5import java.sql.DriverManager;
6import java.sql.SQLException;
7import java.sql.Statement;
8
9import de.ugoe.cs.util.console.Console;
10
11public class MySQLResultStorage implements IResultStorage {
12    private Connection con = null;
13   
14    public MySQLResultStorage() {
15        this("localhost", "3306", "crosspare", "crosspare", "benchmark");
16    }
17   
18    public MySQLResultStorage(String dbHost, String dbPort, String dbName, String dbUser, String dbPass) {
19        try {
20            Class.forName("com.mysql.jdbc.Driver");
21            con = DriverManager.getConnection("jdbc:mysql://" + dbHost + ":" + dbPort + "/" +
22                    dbName + "?" + "user=" + dbUser + "&" + "password=" + dbPass);
23        }
24        catch (ClassNotFoundException e) {
25            Console.printerr("JDBC driver not found");
26        }
27        catch (SQLException e) {
28            Console.printerr("Problem with MySQL connection: ");
29            Console.printerr("SQLException: " + e.getMessage());
30            Console.printerr("SQLState: " + e.getSQLState());
31            Console.printerr("VendorError: " + e.getErrorCode());
32        }
33    }
34
35    public void addResult(ExperimentResult result) {
36        Statement stmt;
37        try {
38            stmt = con.createStatement();
39        }
40        catch (SQLException e) {
41            Console.printerr("Problem with MySQL connection: ");
42            Console.printerr("SQLException: " + e.getMessage());
43            Console.printerr("SQLState: " + e.getSQLState());
44            Console.printerr("VendorError: " + e.getErrorCode());
45            return;
46        }
47        StringBuilder sql = new StringBuilder();
48        sql.append("INSERT INTO crosspare.results VALUES (NULL,");
49        sql.append("\'" + result.getConfigurationName()+"\',");
50        sql.append("\'" + result.getProductName()+"\',");
51        sql.append("\'" + result.getClassifier()+"\',");
52        sql.append(result.getSizeTestData()+",");
53        sql.append(result.getSizeTrainingData()+",");
54        sql.append(result.getSuccHe()+",");
55        sql.append(result.getSuccZi()+",");
56        sql.append(result.getSuccG75()+",");
57        sql.append(result.getSuccG60()+",");
58        sql.append(result.getError()+",");
59        sql.append(result.getRecall()+",");
60        sql.append(result.getPrecision()+",");
61        sql.append(result.getFscore()+",");
62        sql.append(result.getGscore()+",");
63        sql.append(result.getMcc()+",");
64        sql.append(result.getAuc()+",");
65        sql.append(result.getAucec()+",");
66        sql.append(result.getTpr()+",");
67        sql.append(result.getTnr()+",");
68        sql.append(result.getFpr()+",");
69        sql.append(result.getFnr()+",");
70        sql.append(result.getTp()+",");
71        sql.append(result.getFn()+",");
72        sql.append(result.getTn()+",");
73        sql.append(result.getFp()+");");
74        try {
75            stmt.executeUpdate(sql.toString().replace("NaN", "NULL"));
76        }
77        catch (SQLException e) {
78            Console.printerr("Problem with MySQL connection: ");
79            Console.printerr("SQLException: " + e.getMessage());
80            Console.printerr("SQLState: " + e.getSQLState());
81            Console.printerr("VendorError: " + e.getErrorCode());
82            return;
83        }
84    }
85   
86    //public boolean containsResult(String configurationName, String productName, String classifier);
87}
Note: See TracBrowser for help on using the repository browser.