<%-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --%> <%@page import="java.sql.ResultSetMetaData"%> <%@page import="javax.sql.DataSource"%> <%@page import="java.sql.DatabaseMetaData"%> <%@page import="org.springframework.jdbc.datasource.DataSourceUtils"%> <%@page import="java.sql.ResultSet"%> <%@page import="java.sql.Statement"%> <%@page import="java.sql.Connection"%> <%@page import="org.apache.syncope.core.util.ApplicationContextManager"%> <%@page import="org.springframework.context.ConfigurableApplicationContext"%> <%@page contentType="text/html" pageEncoding="UTF-8"%> <%! private void logTableContent(Connection conn, String tableName, JspWriter out) throws Exception { Statement stmt = null; ResultSet rs = null; try { stmt = conn.createStatement(); long size = 0; rs = stmt.executeQuery("SELECT COUNT(*) FROM " + tableName); if (rs.next()) size = rs.getLong(1); rs = stmt.executeQuery("SELECT * FROM " + tableName); ResultSetMetaData metaData = rs.getMetaData(); out.println("Table: " + tableName + ""); out.println(" (" + size + ") "); out.println("Back"); out.println(""); out.println(""); for (int i = 0; i < metaData.getColumnCount(); i++) { out.println(""); } out.println(""); out.println(""); while (rs.next()) { out.println(""); for (int i = 0; i < metaData.getColumnCount(); i++) { if (rs.getString(i + 1) != null && rs.getString(i + 1).length() > 100) { out.println(""); } else { out.println(""); } } out.println(""); } out.println(""); out.println("
" + metaData.getColumnLabel(i + 1) + "
DATA" + rs.getString(i + 1) + "
"); out.println("
"); } catch (Exception e) { throw e; } finally { rs.close(); stmt.close(); } } %> Database content
<% ConfigurableApplicationContext context = ApplicationContextManager.getApplicationContext(); DataSource dataSource = (DataSource) context.getBean("localDataSource"); Connection conn = DataSourceUtils.getConnection( dataSource); DatabaseMetaData dbm = conn.getMetaData(); String[] types = {"TABLE", "VIEW"}; ResultSet rs = dbm.getTables(null, null, "%", types); %>
<% while (rs.next()) { logTableContent(conn, rs.getString("TABLE_NAME"), out); } %>
 
<% rs.close(); conn.close(); %>