zoukankan      html  css  js  c++  java
  • Junit连接oracle数据库

    1.package com.oracle.util;

    import java.sql.Connection;
    import java.sql.DriverManager;
    public class DbUtil { //连接oracle数据库的应用
        private static final String jdbcName="oracle.jdbc.driver.OracleDriver";
        private static final String url="jdbc:oracle:thin:@localhost:1521:ORAC";
        private static final String user="scott";
        private static final String password="tiger";
        public Connection getConn() throws Exception {
            Class.forName(jdbcName);
          /**
           *DriverManager(唯一一个用到的类)
           *Connection(接口)
           */ Connection conn
    =DriverManager.getConnection(url, user, password);                             return conn; } public void closeConn(Connection conn) throws Exception { if(conn!=null){ conn.close(); } } public static void main(String[] args) throws Exception { DbUtil dbUtil=new DbUtil(); Connection conn=dbUtil.getConn(); if(conn!=null){ System.out.println("Oracle数据库连接成功"); }else{ System.out.println("Oracle数据库连接失败"); } dbUtil.closeConn(conn); } }

    2.

    package com.oracle.test;
    
    import static org.junit.Assert.*;
    import java.sql.Connection;
    import org.junit.After;
    import org.junit.Before;
    import org.junit.Test;
    import com.oracle.util.DbUtil;
    
    public class JunitTestOracle { //在Junit中连接oracle数据库 DbUtil dbUtil=new DbUtil(); @Before public void setUp() throws Exception { //setUp()在Junit中用到的方法 } @After public void tearDown() throws Exception { //tearDown()在Junit中用到的方法 } @Test public void test() throws Exception { // 在test()方法中写内容 Connection conn=dbUtil.getConn(); if(conn!=null){System.out.println("Oracle连接成功");} } }
  • 相关阅读:
    网络基础
    socket编程初识
    socket之黏包
    socketserver和socket的补充(验证客户端合法性)
    操作系统介绍
    进程初识和multiprocessing模块之Process
    进程Process之join、daemon(守护)、terminate(关闭)
    进程间通信(队列、管道)、消费者模型和进程池(apply,apply_async,map)
    数字证书私钥sign及验证
    JAVA获取密钥公钥的keytool的使用
  • 原文地址:https://www.cnblogs.com/lxy151/p/8178042.html
Copyright © 2011-2022 走看看