[java]代码库
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class gfhg {
public static void main(String[] args) {
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn=DriverManager.getConnection("jdbc :oracle:thin:@127.0.0.1:1522:orcl1","tangliang","jsd1307");
PreparedStatement ps=conn.prepareStatement("select * from test");
ResultSet rs=ps.executeQuery();
while(rs.next()){
System.out.println(rs.getString(1)+" "+rs.getInt(2));
}
System.out.println(conn);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}catch(SQLException e){
e.printStackTrace();
}
}
}