# JDBC Query Page

Enter your SQL query:
java.sql.* com.bitmechanic.sql.* Form form = request.getForm(); String query = form.getValue("query"); if(query != null && !query.equals("")) { out.println("

"); Connection conn = null; Statement stmt = null; try { // // Get a connection from the pool - username and password are left null conn = DriverManager.getConnection(ConnectionPoolManager.URL_PREFIX + "jdbcalias", null, null); stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(query); ResultSetMetaData metaData = rs.getMetaData(); out.println("

"); out.println("
"); int columnCount = metaData.getColumnCount(); for(int i = 1; i <= columnCount; i++) { out.println(" "+ metaData.getColumnName(i) + ""); } out.println("
"); String bgcolor[] = { "#ffffff", "#cccccc" }; int x = 0; while(rs.next()) { out.println("
"); for(int i = 1; i <= columnCount; i++) { out.println(" " + rs.getString(i) + ""); } out.println("
"); } out.println("

"); rs.close(); stmt.close(); // this doesn't actually close the connection; it returns it back to // the pool for another thread to use conn.close(); } catch(SQLException e) { out.println("

### Error executing Query:

"); out.println("

    " + Logger.exceptionToString(e) + "

"); try { // // return conn to pool -- this prevents a cursor leak if(stmt != null) stmt.close(); if(conn != null) conn.close(); } catch(SQLException e) { } } }