代码部分:
1 @Before 2 public void loadDriver() { 3 try { 4 Class.forName("oracle.jdbc.driver.OracleDriver"); 5 } catch (ClassNotFoundException e) { 6 // TODO Auto-generated catch block 7 e.printStackTrace(); 8 } 9 } 10 11 @Test 12 public void testConn() { 13 String url = "jdbc:oracle:thin:@10.0.0.7:1521:ddgx10g"; // orcl为数据库的SID 14 String user = "njzjdbc"; 15 String password = "123"; 16 17 Properties props = new Properties(); 18 props.put("remarksReporting", "true"); 19 props.put("user", user); 20 props.put("password", password); 21 22 DatabaseMetaData dbmd = null; 23 ResultSet rs = null; 24 Connection dbConn = null; 25 try { 26 dbConn = DriverManager.getConnection(url, props); 27 28 dbmd = dbConn.getMetaData(); 29 30 rs = dbmd.getColumns(dbConn.getCatalog(), "NJZJDBC", "O_NJZJWEB_AJQY_ALL", "%"); 31 32 while (rs.next()) { 33 String columnName = rs.getString("COLUMN_NAME"); 34 String columnRemarks = rs.getString("REMARKS"); 35 System.out.println("columnName:" + columnName 36 + ",columnRemarks:" + columnRemarks); 37 } 38 } catch (SQLException e) { 39 // TODO Auto-generated catch block 40 e.printStackTrace(); 41 }finally{ 42 JdbcUtil.close(rs, null, conn); 43 }
运行结果: