前段时间IBM的超级电脑“沃森”在美国智力竞猜节目《危险边缘》中击败了人类的两位冠军选手。难道电脑比人脑聪明了吗?如此一来我们岂不是失业了!-_- 所以希望您想想看有什么问题是沃森不懂而你懂的。

参考答案:人有感情,电脑没有! 人想象力丰富,电脑没! 人有创新意识,电脑没! 如果算算术的话 电脑比人聪明(主要是速度快)  

	/**
	 * 【店长推荐】商业写法
	 */
	public void testJDBCCommon() {
		// 建立数据库连接对象
		Connection conn = null;
		Statement st = null;
		ResultSet rst = null;
		Driver driver = null;
		try {
			//step 1: 注册驱动到jvm
			driver = new oracle.jdbc.driver.OracleDriver();
			DriverManager.registerDriver(driver);
			//step 2:获取数据库连接; 
			conn = DriverManager.getConnection(
					"jdbc:oracle:thin:@localhost:1521:XE", "hr", "hr");
			//step 3:创建Statement;
			st = conn.createStatement();	
			//step 4:执行查询语句,获取结果集;
			rst = st.executeQuery("select * from employees");
			 //step 5:处理结果集—输出结果集中保存的查询结果; 
			while (rst.next()) {
				System.out.println(rst.getString(1) + "  " + rst.getString(2)
						+ " " + rst.getString("LAST_NAME"));

			}

		} catch (SQLException e) {
			e.printStackTrace();
		} finally {// 无论运行会不会进入到try。。catch代码块,最终都会运行finally代码块
			// 关闭对象,防止多用户环境下挂起问题和锁定问题
			try {
				if (rst != null)
					rst.close();
				if (st != null)
					st.close();
				if (conn != null)
					conn.close();
				driver = null;
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}

	}

  也许不尽人意,大家可以一起探讨。oracle连接数据库,你有几种方式?

/** 
    * @author wonter  
    * <b>描述:</b> 一天学一个模式 更新中,请关注我的weibo! <br>
 
    * <b>微博:</b>:http://weibo.com/wontter
 
<br>
    * <b>邮件:</b> yiyu1@163.com <br>
    */

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-26
  • 2021-12-16
  • 2021-06-16
猜你喜欢
  • 2021-07-12
  • 2021-11-23
  • 2022-12-23
  • 2021-12-31
  • 2021-08-30
  • 2021-09-07
  • 2021-12-20
相关资源
相似解决方案