import java.sql.*;
public class ConnectionTest {
public static void main(String[] arg) {
try {
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url = "jdbc:oracle:thin:@localhost:1521:TEST";
String username = "SMNA";
String password = "SMNA";
Connection conn = DriverManager.getConnection(url, username,
password);
Statement stmt = conn.createStatement();
String sql = "select * from tb_smna_user_info";
ResultSet rs = stmt.executeQuery(sql);
while (rs.next()) {
System.out
.println("Database test" + rs.getString("column_name") == null ? ""
: rs.getString("column_name"));
}
} catch (Exception e) {
System.out.println("err");
}
}
}
注意要导入
jdbc
的驱动
ojdbc14.jar
到
D:\tomcat\common\lib
下