Java(62): Java访问oracle/vertica数据库示例(连接调试用)

Java访问oracle/vertica数据库示例(连接调试用)

Java对于jdbc对数据库的封装,封装方法参考:
1、Java(32):Java对于jdbc对数据库的封装(Bean)https://blog.csdn.net/fen_fen/article/details/120518266

2、Java(31):Java对于jdbc对数据库的封装[2]https://blog.csdn.net/fen_fen/article/details/120469074

3、Java(23):Java对于jdbc对数据库的封装[1]

https://blog.csdn.net/fen_fen/article/details/120379997
 

一、Java访问oracle数据库示例

1、Maven引用(或直接导入jar包)

        <!-- oracle依赖-->

        <dependency>

            <groupId>com.oracle</groupId>

            <artifactId>ojdbc6</artifactId>

            <version>11.2.0.3</version>

        </dependency>

2、连接oracle数据库配置

    static final String JDBC_DRIVER="oracle.jdbc.OracleDriver";

    static final String  DB_URL="jdbc:oracle:thin:@10.1.1.232:1521/ORCL";

    static final String USER = "HMF";

    static final String PASSWORD = "lianshi";

3、连接oracle数据库示例

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

public class oracleSqlTest {

    static final String JDBC_DRIVER="oracle.jdbc.OracleDriver";
    static final String  DB_URL="jdbc:oracle:thin:@10.1.1.232:1521/ORCL";

    static final String USER = "HMF";
    static final String PASSWORD = "lianshi";

    public static void main(String[] args){

        Connection conn = null;
        Statement stmt = null;

        try{
            //注册 JDBC 驱动
            Class.forName(JDBC_DRIVER);
            //打开链接
            System.out.println("Connect DB...");
            conn= DriverManager.getConnection(DB_URL,USER,PASSWORD);

            //执行查询
            System.out.println("实例化Statement对象...");
            stmt = conn.createStatement();
            String sql;
            sql = "SELECT * FROM aoedata";
            ResultSet rs = stmt.executeQuery(sql);

            //展开结果集数据库
            System.out.println("aoeId"+"\t"+"aoeAes"+"\t"+"aoeSm4");
            while (rs.next()){
                System.out.print(rs.getInt(1) + "\t");
                System.out.print(rs.getString(2) + "\t");
                System.out.print(rs.getString(3) + "\t");
                System.out.println();
            }
            rs.close();
            stmt.close();
            conn.close();

        }
        catch(Exception e){
            e.printStackTrace();
        }

    }
}

4、执行结果

 二、Java访问vertica数据库示例

1、Maven引用(或直接导入jar包)

    <dependency>

            <groupId>com.vertica.jdbc</groupId>

            <artifactId>vertica-jdbc</artifactId>

            <version>10.0.1-0</version>

        </dependency>

2、连接vertica数据库配置

    static final String JDBC_DRIVER="com.vertica.jdbc.Driver";

    static final String  DB_URL="jdbc:vertica://10.1.1.215:5433/verticadb?searchPath=cg";

    static final String USER = "dbadmin";

    static final String PASSWORD = "lianShi2021";

3、连接vertica数据库示例

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

public class verticaSqlTest {

    static final String JDBC_DRIVER="com.vertica.jdbc.Driver";
    static final String  DB_URL="jdbc:vertica://10.1.1.215:5433/verticadb?searchPath=cg";

    static final String USER = "dbadmin";
    static final String PASSWORD = "lianShi2021";

    public static void main(String[] args){

        Connection conn = null;
        Statement stmt = null;

        try{
            //注册 JDBC 驱动
            Class.forName(JDBC_DRIVER);
            //打开链接
            System.out.println("Connect DB...");
            conn= DriverManager.getConnection(DB_URL,USER,PASSWORD);

            //执行查询
            System.out.println("实例化Statement对象...");
            stmt = conn.createStatement();
            String sql;
            sql = "SELECT * FROM aoedata";
            ResultSet rs = stmt.executeQuery(sql);

            //展开结果集数据库
            System.out.println("aoeId"+"\t"+"aoeAes"+"\t"+"aoeSm4");
            while (rs.next()){
                System.out.print(rs.getInt(1) + "\t");
                System.out.print(rs.getString(2) + "\t");
                System.out.print(rs.getString(3) + "\t");
                System.out.println();
            }
            rs.close();
            stmt.close();
            conn.close();

        }
        catch(Exception e){
            e.printStackTrace();
        }

    }
}

4、执行结果

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

宁宁可可

您的鼓励是我创作的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值