zoukankan      html  css  js  c++  java
  • 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();
    		}
    	}
    }
    

      

  • 相关阅读:
    wqy的ACM赛G朱柏庐
    可持久化数据结构
    LibreOJ#2362蚯蚓
    LibreOJ#2359天天爱跑步
    「Luogu2221」[HAOI2012]高速公路
    「Luogu4158」[SCOI2009]粉刷匠
    「Luogu4317」花神的数论题
    WC2019 游记
    最大权闭合子图模型
    「Luogu2762」太空飞行计划问题
  • 原文地址:https://www.cnblogs.com/zfc2201/p/2152585.html
Copyright © 2011-2022 走看看