zyl 8 months ago
parent
commit
d9e04dfd6d
1 changed files with 29 additions and 3 deletions
  1. 29 3
      src/main/java/com/citygis/service/BigDataService.java

+ 29 - 3
src/main/java/com/citygis/service/BigDataService.java

@@ -1,13 +1,15 @@
 package com.citygis.service;
-import org.apache.hadoop.fs.FSDataInputStream;
-import org.apache.hadoop.fs.Path;
-import org.apache.hadoop.io.IOUtils;
+
+import com.citygis.mapper.SqlServiceMapper;
+import com.citygis.pojo.SqlService;
 import org.junit.Test;
 
+import javax.annotation.Resource;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.sql.*;
+import java.util.List;
 
 /**
  * @Package com.citygis.service
@@ -17,6 +19,9 @@ import java.sql.*;
  */
 public class BigDataService {
 
+    @Resource
+    SqlServiceMapper sqlServiceMapper;
+
     public static void main(String[] args) throws SQLException, ClassNotFoundException {
         Class.forName("org.apache.hive.jdbc.HiveDriver");
         String jdbcUrl = "jdbc:hive2://192.168.20.6:10000/default";
@@ -120,4 +125,25 @@ public class BigDataService {
             System.out.println("数据库数据成功获取!!");
         }
     }
+
+    public void testSqlserver() throws SQLException, ClassNotFoundException {
+        Class.forName("org.apache.hive.jdbc.HiveDriver");
+        String jdbcUrl = "jdbc:hive2://192.168.20.6:10000/default";
+        Connection conn = DriverManager.getConnection(jdbcUrl);
+
+        PreparedStatement ps = conn.prepareStatement("insert into test1 values (?,?)");
+
+        List<SqlService> all = sqlServiceMapper.getAll();
+
+        for (SqlService sqlService : all) {
+            ps.setString(1, sqlService.getId());
+            ps.setString(2, sqlService.getName());
+            ps.addBatch();
+        }
+
+        boolean execute = ps.execute();
+        ps.close();
+        conn.close();
+    }
+
 }