|
@@ -8,6 +8,7 @@ import static spark.Spark.port;
|
8
|
8
|
import java.sql.Connection;
|
9
|
9
|
import java.sql.DriverManager;
|
10
|
10
|
import java.sql.ResultSet;
|
|
11
|
+import java.sql.SQLException;
|
11
|
12
|
import java.sql.Statement;
|
12
|
13
|
import java.util.ArrayList;
|
13
|
14
|
import java.util.HashMap;
|
|
@@ -18,19 +19,24 @@ import com.google.gson.Gson;
|
18
|
19
|
import kr.co.swh.lecture.opensource.sparkjava.FreeMarkerTemplateEngine;
|
19
|
20
|
|
20
|
21
|
|
21
|
|
-public class DB_newsGet {
|
|
22
|
+public class Step1 {
|
22
|
23
|
|
23
|
|
- static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
|
24
|
|
- static final String DB_URL = "jdbc:mysql://dev-swh.ga:3306/IyHyeon";
|
|
24
|
+ final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
|
|
25
|
+ final String DB_URL = "jdbc:mysql://dev-swh.ga:3306/market";
|
25
|
26
|
|
26
|
|
- static final String USERNAME = "root";
|
27
|
|
- static final String PASSWORD = "swhacademy!";
|
|
27
|
+ final String USERNAME = "root";
|
|
28
|
+ final String PASSWORD = "swhacademy!";
|
28
|
29
|
|
29
|
|
- static Statement stmt;
|
30
|
|
- static ResultSet res;
|
31
|
|
- static Connection conn = null;
|
|
30
|
+ Statement stmt;
|
|
31
|
+ ResultSet res;
|
|
32
|
+ Connection conn = null;
|
32
|
33
|
|
33
|
|
- public static void main(String[] args) {
|
|
34
|
+ public Step1() throws ClassNotFoundException, SQLException {
|
|
35
|
+ Class.forName(JDBC_DRIVER);
|
|
36
|
+ conn = DriverManager.getConnection(DB_URL, USERNAME, PASSWORD);
|
|
37
|
+ }
|
|
38
|
+
|
|
39
|
+ public void excute() {
|
34
|
40
|
port(45678);
|
35
|
41
|
ArrayList<Object> jArr = new ArrayList<Object>();
|
36
|
42
|
Map<String, Object> attributes = new HashMap<>();
|
|
@@ -39,9 +45,10 @@ public class DB_newsGet {
|
39
|
45
|
String acc = request.params("0or1");
|
40
|
46
|
String column = request.params("column");
|
41
|
47
|
String row = request.params("row");
|
42
|
|
- Class.forName(JDBC_DRIVER);
|
43
|
|
- conn = DriverManager.getConnection(DB_URL, USERNAME, PASSWORD);
|
|
48
|
+
|
|
49
|
+ if(conn.isClosed()) conn = DriverManager.getConnection(DB_URL, USERNAME, PASSWORD);
|
44
|
50
|
stmt = conn.createStatement();
|
|
51
|
+
|
45
|
52
|
String acQuery = "select * from NEWS where " + column + " = " + "'" + row + "'";
|
46
|
53
|
String inacQuery = "select * from NEWS where " + column + " like " + "'%" + row + "%'";
|
47
|
54
|
if(acc.equals("1")) res = stmt.executeQuery(acQuery);
|
|
@@ -54,6 +61,19 @@ public class DB_newsGet {
|
54
|
61
|
attributes.put("message", jArr);
|
55
|
62
|
return modelAndView(attributes, "news.ftl");
|
56
|
63
|
}, new FreeMarkerTemplateEngine());
|
|
64
|
+ }
|
|
65
|
+ public static void main(String[] args) {
|
57
|
66
|
|
|
67
|
+ Step1 s;
|
|
68
|
+ try {
|
|
69
|
+ s = new Step1();
|
|
70
|
+ s.excute();
|
|
71
|
+ } catch (ClassNotFoundException e) {
|
|
72
|
+ // TODO Auto-generated catch block
|
|
73
|
+ e.printStackTrace();
|
|
74
|
+ } catch (SQLException e) {
|
|
75
|
+ // TODO Auto-generated catch block
|
|
76
|
+ e.printStackTrace();
|
|
77
|
+ }
|
58
|
78
|
}
|
59
|
79
|
}
|