package com.test;
import java.sql.;
import java.util.;
public class Test {
public static final String DRIVER = "oracle.jdbc.driver.OracleDriver";//oracle 驱动jar包在安装目录D:\ORACLE\product\11.2.0\dbhome_1\oui\jlib\classes12.jar
public static final String URL = "jdbc:oracle:thin:@localhost:1521:orcl";
public static final String USERNAME = "wl";
public static final String PASSWORD = "123456";
public static void main(String[] args) {
Connection conn = null;
try {
Class.forName(DRIVER);// 找到oracle驱动器所在的类
conn = DriverManager.getConnection(URL, USERNAME, PASSWORD);
StringBuffer sql = new StringBuffer();
sql.append("select * from t_user");
PreparedStatement ps = conn.prepareStatement(sql.toString());
ResultSet rs = ps.executeQuery();
while (rs.next()) {
for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) {
System.out.print(rs.getObject(i) + "\t");
}
System.out.println('\n');
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
评论区