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连接成功");} } }
  • 相关阅读:
    感受MapXtreme2004之三:
    GIS集成技术之四:Office, AutoCAD, MatLab集成
    GIS集成技术之二:三库集成
    SQL日期格式化应用大全
    .net中的windows service与服务操作
    大小写转换
    sql系统表syscolumns中 xtype 所有值对应的类型名称
    在.net中读写config文件的各种方法
    VS.NET打包安装
    C#数字格式化输出
  • 原文地址:https://www.cnblogs.com/lxy151/p/8178042.html
Copyright © 2011-2022 走看看