|
@@ -1,6 +1,11 @@
|
1
|
1
|
package kr.co.swh.lecture.opensource.discord.project;
|
2
|
2
|
|
3
|
3
|
import java.io.IOException;
|
|
4
|
+import java.sql.Connection;
|
|
5
|
+import java.sql.DriverManager;
|
|
6
|
+import java.sql.ResultSet;
|
|
7
|
+import java.sql.SQLException;
|
|
8
|
+import java.sql.Statement;
|
4
|
9
|
import java.util.ArrayList;
|
5
|
10
|
import java.util.Arrays;
|
6
|
11
|
import java.util.List;
|
|
@@ -25,7 +30,7 @@ public class SendJDA {
|
25
|
30
|
public static JDA jda;
|
26
|
31
|
public static void main(String[] args) {
|
27
|
32
|
// TODO Auto-generated method stub
|
28
|
|
- List<SentimentalDic> dicList = initDatas();
|
|
33
|
+ List<SentimentalDic> dicList = initDatabase();
|
29
|
34
|
JDABuilder jb = new JDABuilder(AccountType.BOT);
|
30
|
35
|
jb.setAutoReconnect(true);
|
31
|
36
|
jb.setStatus(OnlineStatus.DO_NOT_DISTURB);
|
|
@@ -51,9 +56,6 @@ public class SendJDA {
|
51
|
56
|
response = client.execute(requestGet);
|
52
|
57
|
responseString = EntityUtils.toString(response.getEntity());
|
53
|
58
|
SentimentalDic[] value = gson.fromJson(responseString, SentimentalDic[].class);
|
54
|
|
- for(SentimentalDic dic : value) {
|
55
|
|
- System.out.println(dic.getWord());
|
56
|
|
- }
|
57
|
59
|
dicList.addAll(Arrays.asList(value));
|
58
|
60
|
} catch (IOException e2) {
|
59
|
61
|
// TODO Auto-generated catch block
|
|
@@ -61,4 +63,42 @@ public class SendJDA {
|
61
|
63
|
}
|
62
|
64
|
return dicList;
|
63
|
65
|
}
|
|
66
|
+
|
|
67
|
+ public static List<SentimentalDic> initDatabase(){
|
|
68
|
+ List<SentimentalDic> dicList = new ArrayList<SentimentalDic>();
|
|
69
|
+ Connection connection = null;
|
|
70
|
+ try {
|
|
71
|
+ Class.forName("com.mysql.jdbc.Driver");
|
|
72
|
+ connection = DriverManager.getConnection("jdbc:mysql://dev-swh.ga:3306/market","root","swhacademy!");
|
|
73
|
+ } catch (SQLException e1) {
|
|
74
|
+ // TODO Auto-generated catch block
|
|
75
|
+ e1.printStackTrace();
|
|
76
|
+ } catch (ClassNotFoundException e) {
|
|
77
|
+ // TODO Auto-generated catch block
|
|
78
|
+ e.printStackTrace();
|
|
79
|
+ }
|
|
80
|
+ Statement statement = null;
|
|
81
|
+ try {
|
|
82
|
+ statement = connection.createStatement();
|
|
83
|
+ ResultSet rs = statement.executeQuery("SELECT * FROM SENTIMENTAL_DIC;");
|
|
84
|
+ while(rs.next()){
|
|
85
|
+ SentimentalDic dic = new SentimentalDic();
|
|
86
|
+ dic.setWord_root(rs.getString("word_root"));
|
|
87
|
+ dic.setPolarity(String.valueOf(rs.getInt("polarity")));
|
|
88
|
+ dicList.add(dic);
|
|
89
|
+ }
|
|
90
|
+ rs.close();
|
|
91
|
+ } catch (SQLException e) {
|
|
92
|
+ // TODO Auto-generated catch block
|
|
93
|
+ e.printStackTrace();
|
|
94
|
+ } finally {
|
|
95
|
+ try {
|
|
96
|
+ connection.close();
|
|
97
|
+ } catch (SQLException e) {
|
|
98
|
+ // TODO Auto-generated catch block
|
|
99
|
+ e.printStackTrace();
|
|
100
|
+ }
|
|
101
|
+ }
|
|
102
|
+ return dicList;
|
|
103
|
+ }
|
64
|
104
|
}
|