通过jdbc读取oracle某数据库中的所有表

  • Post author:
  • Post category:其他


public List<T_T_LFHC_TASKUTIL> queryConn(T_T_BDS_RESOURCELIB t) {

	List<T_T_LFHC_TASKUTIL> data = new ArrayList<T_T_LFHC_TASKUTIL>();
	
	String oracleDriverName = "oracle.jdbc.driver.OracleDriver";
	String oracleURL =t.getDblink();
	String oracleUSER = t.getDbuser();
	String oraclePSW = t.getDbpwd();
	Connection conn = null;
	try {
		Class.forName(oracleDriverName);
		Properties props = new Properties();
		props.put("remarksReporting", "true");
		props.put("remarks", "true");
		props.put("user", oracleUSER);
		props.put("password", oraclePSW);
		props.put("driver", oracleDriverName);
		props.put("fetchsize", 100);
		
		conn = DriverManager.getConnection(oracleURL, props);
	
	} catch (Exception e) {
		e.printStackTrace();
	}
	PreparedStatement preparedStatement = null;
	ResultSet resultSet = null;
	try {
		DatabaseMetaData dbmd = conn.getMetaData();
		
		resultSet = dbmd.getTables(conn.getCatalog(),"%", null, new String[] { "TABLE" });
		while (resultSet.next()) {
			T_T_LFHC_TASKUTIL t_T_LFHC_TASKUTIL = new T_T_LFHC_TASKUTIL();
			String name = resultSet.getString("TABLE_NAME");
			String remark = resultSet.getString("REMARKS");
			String user = resultSet.getString("TABLE_SCHEM");
			t_T_LFHC_TASKUTIL.setParam3(name);
			t_T_LFHC_TASKUTIL.setParam2(user);
			t_T_LFHC_TASKUTIL.setParam4(remark);
			data.add(t_T_LFHC_TASKUTIL);
		    //System.out.println("name------>" + name);
		 //   System.out.println("remark------->" + remark);
		}
	} catch (Exception e) {
		e.printStackTrace();
	} finally {
		try {
			if (resultSet != null) {
				resultSet.close();
			}
			if (preparedStatement != null) {
				preparedStatement.close();
			}
			if (conn != null) {
				conn.close();
			}
		} catch (SQLException e) {
			System.err.println(e.getMessage());
		}
	}
	return data;
}

类似的方法也可以取到某人下所有表,以及其他信息

参考

https://www.cnblogs.com/azhqiang/p/4303071.html



版权声明:本文为m0_37987402原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。