Skip to content

Commit aa8aede

Browse files
committed
新增用到的table;优化MySQL连接配置
1 parent cfc1364 commit aa8aede

5 files changed

Lines changed: 184 additions & 13 deletions

File tree

APIJSON(Server)/src/main/java/zuo/biao/apijson/server/sql/SelectTable2.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,13 @@
1212
public class SelectTable2 {
1313
private static final String TAG = "SelectTable2: ";
1414

15+
private static final String YOUR_MYSQL_URL = "jdbc:mysql://localhost:3306/";//TODO edit to an available one
16+
private static final String YOUR_MYSQL_CATALOG = "sys";//TODO edit to an available one
17+
private static final String YOUR_MYSQL_ACCOUNT = "root";//TODO edit to an available one
18+
private static final String YOUR_MYSQL_PASSWORD = "apijson";//TODO edit to an available one
1519

16-
public static void main(String[] args){
17-
// System.out.println(TAG + JSON.toJSONString(select("stu")));
18-
}
19-
20-
private static Connection connection;
21-
private static Statement statement;
22-
private static DatabaseMetaData metaData;
2320
private SelectTable2() {
21+
2422
}
2523

2624
private static SelectTable2 instance;
@@ -31,15 +29,17 @@ public static synchronized SelectTable2 getInstance() {
3129
return instance;
3230
}
3331

34-
3532
public Connection getConnection() throws Exception {
3633
//调用Class.forName()方法加载驱动程序
3734
Class.forName("com.mysql.jdbc.Driver");
3835
System.out.println(TAG + "成功加载MySQL驱动!");
39-
String url="jdbc:mysql://localhost:3306/sys"; //JDBC的URL
40-
return DriverManager.getConnection(url, "root", "199531tommy");
36+
return DriverManager.getConnection(YOUR_MYSQL_URL + YOUR_MYSQL_CATALOG, YOUR_MYSQL_ACCOUNT, YOUR_MYSQL_PASSWORD);
4137
}
4238

39+
40+
private static Connection connection;
41+
private static Statement statement;
42+
private static DatabaseMetaData metaData;
4343
public void close() {
4444
try {
4545
statement.close();

APIJSON(Server)/src/main/java/zuo/biao/apijson/server/sql/SelectTable3.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
public class SelectTable3 {
1515
private static final String TAG = "SelectTable3: ";
1616

17+
private static final String YOUR_MYSQL_URL = "jdbc:mysql://localhost:3306/";//TODO edit to an available one
18+
private static final String YOUR_MYSQL_CATALOG = "sys";//TODO edit to an available one
19+
private static final String YOUR_MYSQL_ACCOUNT = "root";//TODO edit to an available one
20+
private static final String YOUR_MYSQL_PASSWORD = "apijson";//TODO edit to an available one
21+
1722
private Map<String, List<JSONObject>> cacheMap;
1823
private SelectTable3() {
1924

@@ -31,8 +36,7 @@ public Connection getConnection() throws Exception {
3136
//调用Class.forName()方法加载驱动程序
3237
Class.forName("com.mysql.jdbc.Driver");
3338
System.out.println(TAG + "成功加载MySQL驱动!");
34-
String url="jdbc:mysql://localhost:3306/sys"; //JDBC的URL
35-
return DriverManager.getConnection(url, "root", "199531tommy");
39+
return DriverManager.getConnection(YOUR_MYSQL_URL + YOUR_MYSQL_CATALOG, YOUR_MYSQL_ACCOUNT, YOUR_MYSQL_PASSWORD);
3640
}
3741

3842
private void saveCache(String key, List<JSONObject> list) {
@@ -150,7 +154,7 @@ public List<String> getColumnList(String table, DatabaseMetaData meta) {
150154
List<String> list = new ArrayList<String>();
151155
ResultSet rs;
152156
try {
153-
rs = meta.getColumns("sys", null, table, "%");
157+
rs = meta.getColumns(YOUR_MYSQL_CATALOG, null, table, "%");
154158
while (rs.next()) {
155159
System.out.println(TAG + rs.getString(4));
156160
list.add(rs.getString(4));

sys_Comment.sql

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
-- MySQL dump 10.13 Distrib 5.7.12, for osx10.9 (x86_64)
2+
--
3+
-- Host: localhost Database: sys
4+
-- ------------------------------------------------------
5+
-- Server version 5.7.16
6+
7+
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
8+
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
9+
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
10+
/*!40101 SET NAMES utf8 */;
11+
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
12+
/*!40103 SET TIME_ZONE='+00:00' */;
13+
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
14+
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
15+
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
16+
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
17+
18+
--
19+
-- Table structure for table `Comment`
20+
--
21+
22+
DROP TABLE IF EXISTS `Comment`;
23+
/*!40101 SET @saved_cs_client = @@character_set_client */;
24+
/*!40101 SET character_set_client = utf8 */;
25+
CREATE TABLE `Comment` (
26+
`id` int(5) NOT NULL,
27+
`parentId` int(5) NOT NULL,
28+
`workId` int(5) NOT NULL,
29+
`userId` int(5) NOT NULL,
30+
`targetUserId` int(5) NOT NULL,
31+
`content` varchar(1000) DEFAULT NULL,
32+
`targetUserName` varchar(20) NOT NULL,
33+
`userName` varchar(20) NOT NULL,
34+
`title` varchar(60) DEFAULT NULL,
35+
PRIMARY KEY (`id`)
36+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
37+
/*!40101 SET character_set_client = @saved_cs_client */;
38+
39+
--
40+
-- Dumping data for table `Comment`
41+
--
42+
43+
LOCK TABLES `Comment` WRITE;
44+
/*!40000 ALTER TABLE `Comment` DISABLE KEYS */;
45+
INSERT INTO `Comment` VALUES (3,0,371,82002,59960,'This is a Content...-3','targetUserName-59960','userName-85560',NULL),(4,0,470,310,14604,'This is a Content...-4','targetUserName-14604','userName-93781',NULL),(13,0,58,64,6914,'This is a Content...-13','targetUserName-6914','userName-70118',NULL),(22,221,470,332,5904,'This is a Content...-22','targetUserName-5904','userName-11679',NULL),(44,0,170,7073,6378,'This is a Content...-44','targetUserName-6378','userName-88645',NULL),(45,0,301,93793,99700,'This is a Content...-45','targetUserName-99700','userName-30075',NULL),(47,4,470,10,5477,'This is a Content...-47','targetUserName-5477','userName-80271',NULL),(51,45,301,903,8711,'This is a Content...-51','targetUserName-8711','userName-97675',NULL),(54,0,170,3,62122,'This is a Content...-54','targetUserName-62122','userName-82381',NULL),(68,0,371,2314,959,'This is a Content...-68','targetUserName-959','userName-92565',NULL),(76,45,301,93793,42688,'This is a Content...-76','targetUserName-42688','userName-20740',NULL),(77,13,58,90814,35234,'This is a Content...-77','targetUserName-35234','userName-94888',NULL),(97,13,58,90814,14326,'This is a Content...-97','targetUserName-14326','userName-6289',NULL),(99,44,170,793,7166,'This is a Content...-99','targetUserName-7166','userName-22949',NULL),(157,0,371,34,7162,'This is a Content...-13','targetUserName-7162','userName-5526',NULL);
46+
/*!40000 ALTER TABLE `Comment` ENABLE KEYS */;
47+
UNLOCK TABLES;
48+
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
49+
50+
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
51+
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
52+
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
53+
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
54+
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
55+
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
56+
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
57+
58+
-- Dump completed on 2016-11-24 19:27:04

sys_User.sql

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
-- MySQL dump 10.13 Distrib 5.7.12, for osx10.9 (x86_64)
2+
--
3+
-- Host: localhost Database: sys
4+
-- ------------------------------------------------------
5+
-- Server version 5.7.16
6+
7+
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
8+
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
9+
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
10+
/*!40101 SET NAMES utf8 */;
11+
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
12+
/*!40103 SET TIME_ZONE='+00:00' */;
13+
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
14+
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
15+
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
16+
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
17+
18+
--
19+
-- Table structure for table `User`
20+
--
21+
22+
DROP TABLE IF EXISTS `User`;
23+
/*!40101 SET @saved_cs_client = @@character_set_client */;
24+
/*!40101 SET character_set_client = utf8 */;
25+
CREATE TABLE `User` (
26+
`id` int(5) NOT NULL,
27+
`head` varchar(300) DEFAULT NULL,
28+
`name` varchar(20) NOT NULL,
29+
`phone` varchar(14) DEFAULT NULL,
30+
`picture` varchar(3000) DEFAULT NULL,
31+
`sex` int(11) NOT NULL,
32+
PRIMARY KEY (`id`)
33+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
34+
/*!40101 SET character_set_client = @saved_cs_client */;
35+
36+
--
37+
-- Dumping data for table `User`
38+
--
39+
40+
LOCK TABLES `User` WRITE;
41+
/*!40000 ALTER TABLE `User` DISABLE KEYS */;
42+
INSERT INTO `User` VALUES (38710,'http://www.tooopen.com/view/38710.html','Name-38710','1300038710','',0),(70793,'http://www.tooopen.com/view/70793.html','Name-70793','1300070793','',0),(82001,'http://www.tooopen.com/view/82002.html','Name-82002','1300082002','',0),(82002,'http','Name-82002','1300082002','sd',1),(82003,'http://www.tooopen.com/view/82002.html','Name-82002','1300082002','sd',1),(82005,'http://www.tooopen.com/view/82002.html','Name-82002','1300082002','',1),(82006,'http://www.tooopen.com/view/82002.html','Name-82002','1300082002','',1),(82012,'http://www.tooopen.com/view/82002.html','Name-82002','1300082002','',0),(90814,'http://www.tooopen.com/view/90814.html','Name-90814','1300090814','',0),(93793,'http://www.tooopen.com/view/93793.html','Name-93793','1300093793','',0);
43+
/*!40000 ALTER TABLE `User` ENABLE KEYS */;
44+
UNLOCK TABLES;
45+
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
46+
47+
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
48+
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
49+
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
50+
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
51+
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
52+
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
53+
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
54+
55+
-- Dump completed on 2016-11-24 19:27:04

sys_Work.sql

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
-- MySQL dump 10.13 Distrib 5.7.12, for osx10.9 (x86_64)
2+
--
3+
-- Host: localhost Database: sys
4+
-- ------------------------------------------------------
5+
-- Server version 5.7.16
6+
7+
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
8+
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
9+
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
10+
/*!40101 SET NAMES utf8 */;
11+
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
12+
/*!40103 SET TIME_ZONE='+00:00' */;
13+
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
14+
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
15+
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
16+
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
17+
18+
--
19+
-- Table structure for table `Work`
20+
--
21+
22+
DROP TABLE IF EXISTS `Work`;
23+
/*!40101 SET @saved_cs_client = @@character_set_client */;
24+
/*!40101 SET character_set_client = utf8 */;
25+
CREATE TABLE `Work` (
26+
`id` int(5) NOT NULL,
27+
`title` varchar(45) DEFAULT NULL,
28+
`content` varchar(300) DEFAULT NULL,
29+
`userId` int(5) NOT NULL,
30+
`picture` varchar(3000) NOT NULL,
31+
PRIMARY KEY (`id`)
32+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
33+
/*!40101 SET character_set_client = @saved_cs_client */;
34+
35+
--
36+
-- Dumping data for table `Work`
37+
--
38+
39+
LOCK TABLES `Work` WRITE;
40+
/*!40000 ALTER TABLE `Work` DISABLE KEYS */;
41+
INSERT INTO `Work` VALUES (58,'Title-435','This is a Content...-435',90814,'http://www.tooopen.com/view/435.html'),(170,'Title-73','This is a Content...-73',70793,'http://www.tooopen.com/view/73.html'),(301,'Title-301','This is a Content...-301',93793,'http://www.tooopen.com/view/301.html'),(371,'Title-371','This is a Content...-371',82002,'http://www.tooopen.com/view/371.html'),(470,'Title-470','This is a Content...-470',38710,'http://www.tooopen.com/view/470.html');
42+
/*!40000 ALTER TABLE `Work` ENABLE KEYS */;
43+
UNLOCK TABLES;
44+
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
45+
46+
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
47+
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
48+
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
49+
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
50+
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
51+
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
52+
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
53+
54+
-- Dump completed on 2016-11-24 19:27:04

0 commit comments

Comments
 (0)