jdbc for oracle demo

package com.huawei.oracle;
 
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
 
public class OracleTest {
    public static void main(String[] args) throws SQLException {
        Connection conn = null;
        PreparedStatement stmt = null;
        ResultSet rs = null;
 
        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            conn = DriverManager.getConnection(
                    "jdbc:oracle:thin:@localhost:1521:orcl", "scott", "tiger");
            stmt = conn.prepareStatement("select * from emp where deptno=?");
            stmt.setInt(1, 10);
            rs = stmt.executeQuery();
            while (rs.next()) {
                System.out.println(rs.getInt("empno"));
                System.out.println(rs.getString("ename"));
                System.out.println(rs.getString("job"));
                System.out.println(rs.getInt("mgr"));
                System.out.println(rs.getDate("hiredate"));
                System.out.println(rs.getInt("sal"));
                System.out.println(rs.getInt("comm"));
                System.out.println(rs.getInt("deptno"));
                System.out.println("----------------------------");
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        finally
        {
            if(rs!= null) rs.close();
            if(stmt!= null) stmt.close();
            if(conn != null) conn.close();
        }
    }
}

  

posted @   水之原  阅读(1574)  评论(0编辑  收藏  举报
编辑推荐:
· 智能桌面机器人:用.NET IoT库控制舵机并多方法播放表情
· Linux glibc自带哈希表的用例及性能测试
· 深入理解 Mybatis 分库分表执行原理
· 如何打造一个高并发系统?
· .NET Core GC压缩(compact_phase)底层原理浅谈
阅读排行:
· 新年开篇:在本地部署DeepSeek大模型实现联网增强的AI应用
· DeepSeek火爆全网,官网宕机?本地部署一个随便玩「LLM探索」
· Janus Pro:DeepSeek 开源革新,多模态 AI 的未来
· 互联网不景气了那就玩玩嵌入式吧,用纯.NET开发并制作一个智能桌面机器人(三):用.NET IoT库
· 上周热点回顾(1.20-1.26)
点击右上角即可分享
微信分享提示