1 package xsl; 2 3 import java.sql.Connection; 4 import java.sql.DriverManager; 5 import java.sql.PreparedStatement; 6 import java.sql.ResultSet; 7 8 public class Test { 9 public static void main(String[] args) throws Exception { 10 //加载数据包 11 Class.forName("oracle.jdbc.driver.OracleDriver"); 12 //开始连接 13 Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:orcl","xsl","xsl"); 14 //准备sql语句 15 PreparedStatement pstmt = conn.prepareStatement("select * from student"); 16 //执行sql语句 17 ResultSet rs = pstmt.executeQuery(); 18 while(rs.next()){ 19 System.out.println(rs.getString(1)+" "+rs.getString(2)); 20 } 21 rs.close(); 22 pstmt.close(); 23 // PreparedStatement pstmt = conn.prepareStatement("insert into student(sname,sid) values ('xxx',2013550400)"); 24 // pstmt.executeUpdate(); 25 // pstmt.close(); 26 conn.close(); 27 28 } 29 30 }