jdbc连接oracle数据库

/*** jdbc连接oracle数据库/
1 package com.xykj.jdbc; import static org.junit.Assert.;
import java.sql.
;
import java.util.Properties; import org.junit.Test; public class JDBCTest { /

  * Driver是一个接口:数据库厂商必须提供实现的接口,能从其中获取数据库连接。<br/>
  *   1.加入oracle驱动<br/>
  *    1&gt;新建lib目录,复制粘贴jar包放入lib。<br/>
  *    2&gt;右键jar包,build path,add  加入到类路径下。<br/>
  */<br/>
 @Test<br/>
 public void testDriver()  {<br/>
     ResultSet res=null;           //创建一个结果集对象<br/>
     PreparedStatement pre = null; //创建预编译语句对象,一般都是用这个而不用Statement<br/>
     Connection connection = null; //创建一个数据库连接<br/>
   try<br/>
   {

//1.创建一个Driver实现类的对象

     Driver driver = new oracle.jdbc.driver.OracleDriver();  //加载Oracle驱动程序

//2.准备连接数据库的基本信息:url,user,password

     String url = &#34;jdbc:oracle:thin:@127.0.0.1:1521:orcl&#34;;<br/>
     Properties info = new Properties();<br/>
     info.put(&#34;user&#34;, &#34;system&#34;);<br/>
     info.put(&#34;password&#34;, &#34;sys&#34;);

//3.调用Driver接口的connect(url,info)获取数据库连接

     connection = driver.connect(url, info);  //获取连接<br/>
     System.out.println(connection);<br/>
     System.out.println(&#34;数据库连接成功!&#34;);

//4.对数据库进行操作

     String sql = &#34;select * from Stu where Name = ?&#34;;  //预编译语句,?代表参数<br/>
     pre = connection.prepareStatement(sql);  //实例化预编译语句<br/>
     pre.setString(1, &#34;张三&#34;);  // 设置参数,前面的1表示参数的索引,而不是表中列名的索引<br/>
     res = pre.executeQuery(); //执行查询<br/>
     while(res.next())

System.out.println(“姓名:”+res.getString(“name”)

                          + &#34;性别:&#34;+res.getString(&#34;sex&#34;)<br/>
                          + &#34;年龄:&#34;+res.getString(&#34;age&#34;));<br/>
   }<br/>
 catch (Exception e )<br/>
 {<br/>
     e.printStackTrace();<br/>
 }<br/>
   finally<br/>
   {<br/>
       try<br/>
       {<br/>
         // 逐一将上面的几个对象关闭,因为不关闭的话会影响性能、并且占用资源<br/>
         // 注意关闭的顺序,最后使用的最先关闭<br/>
           if(res != null)<br/>
               res.close();<br/>
           if(pre != null)<br/>
               pre.close();<br/>
           if(connection != null)<br/>
               connection.close();<br/>
           System.out.println(&#34;数据库连接已关闭!&#34;);<br/>
       }<br/>
       catch(Exception e){<br/>
           e.printStackTrace();<br/>
       }<br/>
   }<br/>

}
}