MPP的API操作数据

代码实例

package oa.epoint.com.mppdb;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

import com.MPP.jdbc.jdbc2.optional.MPPDataSource;

public class MPPTest {
    // JDBC连接串
        static String url = "jdbc:MPP://100.2.5.1:5258/";
        // mpp用户名
        static String user = "mpp";
        // mpp密码
        static String passwd = "h3c";

        public static void main(String args[]) {
            Connection conn = null;
            Statement st = null;
            ResultSet rs = null;
            try {
                Class.forName("com.MPP.jdbc.Driver");
                // 创建连接
                MPPDataSource ds = new MPPDataSource();
                ds.setUrl(url);
                ds.setUser(user);
                ds.setPassword(passwd);
                conn = ds.getConnection();
                System.out.println("MPP连接成功!");
                st = conn.createStatement();
                //创建库
                st.execute("create database if not exists test;");
                System.out.println("创建数据库成功!");
                //使用库
                st.execute("use test;");
                System.out.println("使用数据库成功!");
                //创建表
                st.execute("create table if not exists test (id int,name varchar(20),age int);");
                System.out.println("创建表成功!");
                //插入数据
                st.execute("insert into test values(1,'test',15)");
                System.out.println("插入数据成功!");
                // 查询TEST表内容
                rs = st.executeQuery("SELECT * FROM test");
                System.out.println("查询数据成功,等待反馈结果!");
                while (rs.next()) {
                    System.out.print(rs.getString(1));
                    System.out.print("  ");
                    System.out.println(rs.getString(2));
                }
                rs.close();
                st.close();
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                // 关闭连接
                if (conn != null) {
                    try {
                        conn.close();
                        conn = null;
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
jdbc:MPP://100.2.5.2:5258/test?rewriteBatchedStatements=true
com.MPP.jdbc.Driver

这里写图片描述

你可能感兴趣的:(MPP的API操作数据)