package jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Test {
public static void main(String[] args) {
}
static void TestJdbc() throws ClassNotFoundException, SQLException{
//注册驱动
Class.forName("oracle.jdbc.driver.OracleDriver");
//建立连接
Connection conn=DriverManager.getConnection("jdbc:oracle:localhost:9999:orcl","scott","123");
//创建语句
Statement s=conn.createStatement();
//执行语句
ResultSet rs=s.executeQuery("select ename from emp ");
while(rs.next()){
System.out.println(rs.getString("ename"));
}
rs.close();
s.close();
conn.close();
}
}
|