今天第一天接触大数据 做一些基本的增删改差,来这总结一下 ,资源来自网络本人属于收藏总结

这一篇只有demo合运行结果 ,下一篇有一点对代码的分析合自己的理解

先看一下数据库 的数据

 

查询数据

 1   public static void main(String args[]) throws TRSException {
 2             TRSConnection conn = new TRSConnection("http://127.0.0.1:5555", "admin", "trsadmin", new ConnectParams());
 3             SearchParams param = new SearchParams();
 4             param.setReadColumns("rowid;日期;标题;作者;正文");
 5             param.setColorColumns("正文");
 6             param.setCutSize(200);
 7             TRSResultSet resultSet = conn.executeSelect("demo", "正文:街舞", 0, 10, param);
 8 
 9             System.out.println(resultSet.getNumFound() + " records found");
10             for (int i = 0; i < resultSet.size(); i++) {
11                 resultSet.moveNext();//移动到检索结果记录集的下一条记录。
12                 TRSRecord re = resultSet.get();
13                 System.out.println();
14                 System.out.println("result_" + i);
15                 System.out.println("rowid:" + re.getString("rowid"));
16                 System.out.println("日期:" + re.getString("日期"));
17                 System.out.println("标题:" + re.getString("标题"));
18                 System.out.println("作者:" + re.getString("作者"));
19                 System.out.println("正文:" + re.getString("正文"));
20             }
21             conn.close();
22         }


 

后台输出结果

增加数据

 1 public class DemoAdd {
 2 
 3     /**
 4      * @param args
 5      * @throws TRSException 
 6      */
 7     public static void main(String[] args) throws TRSException {
 8         // TODO Auto-generated method stub
 9           TRSConnection conn = new TRSConnection("http://127.0.0.1:5555", "admin", "trsadmin", new ConnectParams());
10             List<TRSInputRecord> recordList = new ArrayList<TRSInputRecord>();
11             TRSInputRecord record_1 = new TRSInputRecord();
12             record_1.addColumn("rowid", "1");
13             record_1.addColumn("日期", "2018-03-15");
14             record_1.addColumn("版次", "1");
15             record_1.addColumn("版名", "娱乐");
16             record_1.addColumn("标题", "街舞少年尬舞,输的要吃要吃掉对方的帽子");
17             record_1.addColumn("作者", "张邦煊");
18             record_1.addColumn("正文", "新疆乌鲁木齐街舞少年 日前在南湖广场高调尬舞,扬言输掉要吃掉对方的帽子");
19             recordList.add(record_1);
20 
21             TRSInputRecord record_2 = new TRSInputRecord();
22             record_2.addColumn("rowid", "2");
23             record_2.addColumn("日期", "2018.3.15");
24             record_2.addColumn("版次", "3 ");
25             record_2.addColumn("版名", "娱乐");
26             record_2.addColumn("标题", "ks舞社再次蝉联九届WID冠军");
27             record_2.addColumn("作者", "张邦煊");
28             record_2.addColumn("正文", "ks舞社队长 嘎子说:“我们已经是连续九届的冠军了, 拿的手都软了”");
29             recordList.add(record_2);
30 
31             OperationParams params = new OperationParams();
32             params.setBoolProperty("insert.skip.error", true);
33             TRSReport report = new TRSReport();
34             try {
35                 conn.executeInsert("demo", recordList,params, report);//插入数据 demo表名  recordList数据
36                 conn.commitDatabase("demo", new OperationParams());//提交
37                 System.out.println("insert records:" + report.getInsertedNum());//插入成功的数目 如果 executeInsert方法不写 后面的两个参数 则此处置为 0
38             } catch (TRSException e) {
39                 System.out.println(e.getErrorCode() + ":" + e.getErrorString());
40             } finally {
41                 conn.close();
42             }
43         }
44         
45                 
46 
47     }

 这个就不运行了 

删除数据

public class DemoDel {

    /**
     * @param args
     * @throws TRSException 
     */
    public static void main(String[] args) throws TRSException {
        // TODO Auto-generated method stub
        TRSConnection conn = new TRSConnection("http://127.0.0.1:5555", "admin", "trsadmin", new ConnectParams());
        SearchParams param = new SearchParams();
        param.setReadColumns("rowid;日期;标题;作者;正文");
        param.setColorColumns("标题");//高亮显示
        param.setCutSize(200);
        TRSResultSet resultSet = conn.executeSelect("demo", "版次:1", 0, 10, param);
        
        System.out.println(resultSet.getNumFound());
//        for (int i = 0; i < resultSet.size(); i++) {
//            resultSet.moveNext();//移动到检索结果记录集的下一条记录。
//            TRSRecord re = resultSet.get();
//            System.out.println();
//            System.out.println("result_" + i);
//            System.out.println("rowid:" + re.getString("rowid"));
//            System.out.println("日期:" + re.getString("日期"));
//            System.out.println("标题:" + re.getString("标题"));
//            System.out.println("作者:" + re.getString("作者"));
//            System.out.println("正文:" + re.getString("正文"));
//        }
        
        for (int i = 0; i < resultSet.size(); i++) {
            resultSet.moveNext();
            TRSRecord re = resultSet.get();
            conn.executeDelete("demo", re.getUid());
        }
        conn.close();
    }

    }

后台结果 

数据库的结果

修改数据

 1 public class DemoUpdate {
 2 
 3     /**
 4      * @param args
 5      * @throws TRSException -        
 6      */
 7     public static void main(String[] args) throws TRSException {
 8         // TODO Auto-generated method stub
 9           TRSConnection conn = new TRSConnection("http://127.0.0.1:5555", "admin", "trsadmin", new ConnectParams());
10             SearchParams sParams = new SearchParams();
11             TRSResultSet resultSet = conn.executeSelect("demo", "版名:娱乐", 0, 1, sParams);//查询
12             System.out.println(resultSet.getNumFound());
13             resultSet.moveNext();//下一个
14             TRSRecord re = resultSet.get();//取当前一条记录
15             TRSInputRecord updated = new TRSInputRecord();
16             updated.setUid(re.getUid());
17             updated.addColumn("正文", "update=================");
18             ArrayList<TRSInputRecord> updateList = new ArrayList<TRSInputRecord>(1);
19             updateList.add(updated);
20             OperationParams uParams = new OperationParams();
21             uParams.setProperty("update.mode.replace", "false");
22             conn.executeUpdate("demo", updateList,uParams,new TRSReport());
23             conn.close();
24 
25         
26         
27     }
28 
29 }

运行前的数据库 

 

运行后

 

后台打印