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

  

相关文章:

  • 2021-10-02
  • 2021-08-17
  • 2022-12-23
  • 2021-07-14
  • 2021-12-15
  • 2022-01-09
猜你喜欢
  • 2021-05-25
  • 2021-11-23
  • 2021-05-24
  • 2022-02-27
  • 2022-12-23
  • 2021-11-16
  • 2021-07-28
相关资源
相似解决方案