📄 opendb.java
字号:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.sql.*;
import Angel.ServerConfig;
import Base.Action.*;
import Base.DataBean.*;
import Base.ServletCtl.servlet;
/**
* This is a simple example of an HTTP Servlet. It responds to the GET
* and HEAD methods of the HTTP protocol.
*/
public class OpenDb extends Action
{
DefaultDataBean m_dBean = null;
//交易处理的入口函数,
//参数: DefaultDataBean类的实例
//返回值:0 - 出错,错误原因放在key: Action.perform.errReason, value:为String类
// 错误代码放在key: Action.perform.errCode, value:为Integer类
// 1 - 成功,可以继续执行后一个交易
public int perform(DefaultDataBean dBean) throws IOException, ServletException
{
m_dBean = dBean;
try {
// Load the Oracle JDBC driver
// DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
// Connect to the database
// You must put a database name after the @ sign in the connection URL.
// You can use either the fully specified SQL*net syntax or a short cut
// syntax as <host>:<port>:<sid>. The example uses the short cut syntax.
// Connection con = DriverManager.getConnection("jdbc:oracle:thin:@192.168.10.227:1521:communit", "blues", "blues");
String dbUrl = "jdbc:odbc:angel";
String dbDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String strUser = "sa";
String strPass = "1";
Connection con = null;
ServerConfig sc = null;
sc = new ServerConfig(m_servlet, m_request);
if(sc==null){
setError(500,"ServerConfig error");
return 0;
}
//刘中兵修改
dbUrl = sc.getStrDBURL();
dbDriver = sc.getStrDBDriver();
strUser = sc.getStrDBUser();
strPass = sc.getStrDBPass();
System.out.println(dbUrl+"="+dbDriver+"="+strUser+"="+strPass);
dbUrl = com.parser.Configuration.DB_URL + "?useUnicode=true&characterEncoding=gb2312";
dbDriver = com.parser.Configuration.DB_JDBCDRIVER;
strUser = com.parser.Configuration.DB_USERNAME;
strPass = com.parser.Configuration.DB_PASSWORD;
System.out.println(dbUrl+"="+dbDriver+"="+strUser+"="+strPass);
System.out.println("connect="+dbUrl + " " + dbDriver + strUser + strPass);
Class.forName(dbDriver);
con = DriverManager.getConnection(dbUrl, strUser, strPass);
Statement stmt= con.createStatement();
dBean.putAttribute("Action.perform.Connect",con);
dBean.putAttribute("Action.perform.Statement",stmt);
}
catch(Exception e){
dBean.putAttribute("Action.perform.errReason",new String(e.getMessage().getBytes("gb2312"),"8859_1" ) );
dBean.putAttribute("Action.perform.errCode",new Integer(1000) );
setError(500,e.getMessage());
m_servlet.log("OpenDb:",e);
return 0;
}
return 1;
}
void setError(int errCode, String errReason) {
if (m_dBean != null) {
if (errReason == null) {
errReason = new String("");
errCode = 101;
}
m_dBean.putAttribute("Action.perform.errReason", errReason);
m_dBean.putAttribute("Action.perform.errCode", new Integer(errCode));
m_servlet.log(2, "Action report error: " + errReason);
}
return;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -