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();
    		}
    	}
    }
    

      

  • 相关阅读:
    hiveserver2 with kerberos authentication
    python Basic usage
    python Quicksort demo
    Python HeapSort
    mrunit for wordcount demo
    CCDH证书
    Hadoop question list
    Hadoop Yarn core concepts
    Hadoop Resource
    Hadoop could not find or load main class
  • 原文地址:https://www.cnblogs.com/zfc2201/p/2152585.html
Copyright © 2011-2022 走看看