-
Notifications
You must be signed in to change notification settings - Fork 0
/
DataWriter.java
54 lines (48 loc) · 1.73 KB
/
DataWriter.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
46
47
48
49
50
51
52
53
54
package C212Amazon;
import java.sql.*;
/**
* Abstract class for file writers.
* @author Syed Turab Ali Jafri
* 4/14/2017
*/
public class DataWriter {
public Connection databaseConnector(){
Connection connection = null;
try {
Class.forName("com.mysql.jdbc.Driver");
//connection = DriverManager.getConnection("jdbc:mysql://localhost/amazon", "root", "password");
connection = DriverManager.getConnection("jdbc:mysql://db.soic.indiana.edu/c212s17_aalimov", "c212s17_aalimov", "Guu37gu6");
} catch (Exception e) {
e.printStackTrace();
}
return connection;
}
public void setDb(String table, String column, int id, String input){
String sqlQuery = "UPDATE " + table + " SET " + table + "." + column + " = '" + input +
"' WHERE " + table + ".id = " + id;
try{
Connection conn = databaseConnector();
Statement query = conn.createStatement();
System.out.println(sqlQuery);
query.executeUpdate(sqlQuery);
conn.close();
}
catch (Exception e){
System.err.println(e.getMessage());
}
}
public void setDb(String table, String column, int id, int input){
String sqlQuery = "UPDATE " + table + " SET " + table + "." + column + " = '" + input +
"' WHERE " + table + ".id = " + id;
try{
Connection conn = databaseConnector();
Statement query = conn.createStatement();
System.out.println(sqlQuery);
query.executeUpdate(sqlQuery);
conn.close();
}
catch (Exception e){
System.err.println(e.getMessage());
}
}
}