-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProcessDictionary.java
More file actions
128 lines (116 loc) · 3.92 KB
/
ProcessDictionary.java
File metadata and controls
128 lines (116 loc) · 3.92 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import java.io.*;
import java.sql.*;
public class ProcessDictionary
{
public static void main(String[] args)
{
try
{
//Create buffered input stream.
InputStreamReader isr = new InputStreamReader(System.in);
System.out.println("ProcessDictionary : input stream reader opened !");
//Create buffered reader.
BufferedReader br = new BufferedReader(isr);
System.out.println("ProcessDictionary : buffered reader opened !");
//Load driver.
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
System.out.println("ProcessDictionary : driver loaded !");
//Open connection.
String url = "jdbc:sqlserver://localhost:1433;databaseName=nldb";
String user = "sa";
String password = "forest_luo";
Connection connection = DriverManager.getConnection(url, user, password);
System.out.println("ProcessDictionary : connection opened !");
//Create insert statement.
CallableStatement insertStatement =
connection.prepareCall("{CALL dbo.ContentInsertValue(?)}");
//Create delete statement.
CallableStatement deleteStatement =
connection.prepareCall("{CALL dbo.ContentDeleteValue(?)}");
//Create select statement.
PreparedStatement selectStatement =
connection.prepareStatement("SELECT content, count FROM " +
"( " +
"SELECT DISTINCT content,count FROM dbo.Dictionary WHERE enable = 1 AND count > 0 AND length > 1 " +
") AS T " +
"WHERE dbo.ContentGetCID(content) <= 0 AND " +
"content NOT IN " +
"( " +
"SELECT DISTINCT content FROM dbo.Dictionary WHERE length > 1 AND classification IN " +
"('公司','公司缩写','名人','姓名','姓氏','日文名','新华字典','现代汉语词典','组织结构','成语') " +
") ORDER BY count DESC;");
System.out.println("ProcessDictionary : statement opened !");
//Execute statement.
ResultSet rs = selectStatement.executeQuery();
System.out.println("ProcessDictionary : resultset opened !");
boolean exit = false;
//Do loop process.
while(!exit && rs.next())
{
//Get count.
int count = rs.getInt("count");
//Get content.
String content = rs.getString("content");
//Print result.
System.out.println("> count(\"" + content + "\") = " + count);
//Do while.
do
{
//Wait for input.
String line = br.readLine();
//Check result.
if(line == null || line.length() <= 0) break;
//Check command.
if(line.equals("exit"))
{
System.out.println("> exit !"); exit = true;
}
else if(line.equals("d"))
{
//Set parameter.
deleteStatement.setString(1, content);
//Execute.
deleteStatement.executeUpdate();
//Print.
System.out.println("> content(\"" + content + "\") was deleted !"); break;
}
else if(line.equals("i"))
{
//Set parameter.
insertStatement.setString(1, content);
//Execute.
insertStatement.executeUpdate();
//Print.
System.out.println("> content(\"" + content + "\") was inserted !"); break;
}
else
{
System.out.println("> invalid command(" + line + ")");
}
}while(!exit);
}
//Close result set.
rs.close();
System.out.println("ProcessDictionary : resultset closed !");
//Close statement.
selectStatement.close();
deleteStatement.close();
insertStatement.close();
System.out.println("ProcessDictionary : statement closed !");
//Close connection.
connection.close();
System.out.println("ProcessDictionary : connection closed !");
//Close buffered reader.
br.close();
System.out.println("ProcessDictionary : buffered reader closed !");
//Close buffered input stream.
isr.close();
System.out.println("ProcessDictionary : input stream reader closed !");
}
catch(Exception e)
{
System.out.println("ProcessDictionary : " + e.getMessage());
System.out.println("ProcessDictionary : unexpected exit !");
}
}
}