import java.sql.*;
public class JdbcUtil
{
static{
String driverName="oracle.jdbc.driver.OracleDriver";
try{
Class.forName(driverName);
}catch(Exception e){
System.out.println(e.getMessage());
}
}
public static Connection getConnection(){
String url =
"jdbc:oracle:thin:@"+
"192.168.0.20:1521:tarena";
String userName = "openlab";
String pwd = "open123";
Connection con = null;
try{
con = DriverManager.getConnection(
url,userName,pwd);
}catch(Exception e){
System.out.println(e.getMessage());
}
return con;
}
public static void close(ResultSet rs,
Statement stmt,
Connection con){
try{
if(rs!=null) rs.close();
}catch(Exception ex){
ex.printStackTrace();
}
try{
if(stmt!=null) stmt.close();
}catch(Exception ex){
ex.printStackTrace();
}
try{
if(con!=null) con.close();
}catch(Exception ex){
ex.printStackTrace();
}
}
public static Integer parseInt(String s){
Integer i = null;
try{
i = Integer.parseInt(s);
}catch(Exception e){
System.out.println(e.getMessage());
}
return i;
}
public static void printRs(ResultSet rs){
if(rs==null){
System.out.println("结果集为null");
return;
}
try{
StringBuffer sb = new StringBuffer();
ResultSetMetaData meta = rs.getMetaData();
int cols = meta.getColumnCount();
/*for(int i=1;i<=cols;i++){
sb.append(meta.getColumnName(i)+"->");
sb.append(meta.getColumnType(i)+"(");
sb.append(meta.getColumnTypeName(i)+")/n");
}*/
while(rs.next()){
for(int i=1;i<=cols;i++){
sb.append(meta.getColumnName(i)+"=");
sb.append(rs.getString(i)+" ");
}
sb.append("/n");
}
System.out.print(sb.toString());
}catch(Exception e){
System.out.println(e.getMessage());
}
}
}