zoukankan      html  css  js  c++  java
  • jdbc+oracle测试类。

    package org.portal.service;

    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    /**
    * 测试连接oracle数据库
    * @author wpc
    *
    */

    public class Test {
    //驱动,URL,用户名,密码
    private static final String driver = "oracle.jdbc.driver.OracleDriver";
    private static final String url = "jdbc:oracle:thin:@localhost:1521:orcl";
    private static final String username = "zjuser";
    private static final String password = "zjpass";

    public static Connection getConnection() {
    Connection connection = null;
    try {
    // 加 载驱动
    Class.forName(driver);
    // 通过驱动管理类获取数据库连接
    connection = DriverManager.getConnection(url, username, password);
    // 关闭连接
    //connection.close();
    } catch (ClassNotFoundException e) {
    e.printStackTrace();
    } catch (Exception e) {
    e.printStackTrace();
    }
    return connection;
    }

    // 测试oracle连接是否成功
    public static void main(String[] args) throws SQLException {
    Connection connection = Test.getConnection();
    if (connection != null) {
    System.out.println("连接oracle数据库成功:" + connection);
    //这里具体查询数据库中的数据,可以直接取出。
    /* String sql = "select * FROM BUSER";
    Statement st = connection.createStatement();
    st.executeQuery(sql);
    ResultSet rs = st.executeQuery(sql);
    if(rs.next()){
    String name = rs.getString("NAME");
    System.out.println("name"+name);
    }
    connection.close();*/
    } else {
    System.out.println("连接oracle数据库失败!!!");
    }


    }
    }

    //要引入jdbc.jar包

    https://files.cnblogs.com/files/cyz110/jdbc6.rar

  • 相关阅读:
    MySQL-keepalived做高可用
    Linux-服务管理
    MySQL-CentOS7上安装Mysql5.7
    MySQL-查看DB文件位置
    游戏编程与游戏种类
    计算机
    python
    python中的构造函数
    IndentationError:expected an indented block错误解决
    python程序的pdb调试方法
  • 原文地址:https://www.cnblogs.com/cyz110/p/8695441.html
Copyright © 2011-2022 走看看