分类: Oracle
2012-04-13 23:21:31
package oracle0;
import java.sql.*;
public class TestOracle02 {
//使用JDBC连接数据库
public static void main(String[] args) {
//有异常先解决异常
try {
//1.加载驱动
Class.forName("oracle.jdbc.driver.OracleDriver"); //注意大小写
//2.得到连接
Connection ct=DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:shujiku","scott","ptyh");
//3.上面的也一样
Statement sm=ct.createStatement();
ResultSet rs=sm.executeQuery("select * from emp");
while(rs.next())
{
System.out.println("姓名是:"+rs.getString(2));
}
} catch (Exception e) {
e.printStackTrace(); //打印异常
}
}