// You can use this sample servlet as a starting point to connect
//簡單servlet連結oracle修改語法。
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
public
class Ex63 extends HttpServlet {
/**
*
*/
private static final long serialVersionUID = 1L;
public void service(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
res.setContentType("text/html;charset=utf-8");
ServletOutputStream sos = res.getOutputStream();
PrintWriter out = new PrintWriter(sos,true);
out.println("<html>");
out.println("<head><title>Hello World</title></head>");
out.println("<body>");
try {
// The newInstance() call is a work around for some
// broken Java implementations
out.println("測試");
Class.forName("oracle.jdbc.OracleDriver").newInstance();
}
catch (Exception E) {
out.println("Unable to load driver.");
E.printStackTrace();
}
out.println("<br><hr>");
try {
Connection Conn =
DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:orcl","user","password");
// Do something with the Connection
Statement Stmt = Conn.createStatement();
ResultSet RS = Stmt.executeQuery("SELECT var1 from testtable");
String nameStr = req.getParameter("Name");
String sql2 = "insert into testtable(var1) values('"+nameStr+"')";
//DatabaseMetaData dm = Conn.getMetaData();
//ResultSet tb = dm.getTables(null,null,"testtable",null);
if(nameStr!=null&&nameStr!=""){
Stmt.executeUpdate(sql2);
out.println("有執行sql2<br>");
}
while (RS.next()) {
out.println(RS.getString(1));
}
out.println("<br><hr>");
out.println("你輸入的字串是"+nameStr+"<br>");
out.println("你輸入的sql語法是"+sql2+"<br>");
// Clean up after ourselves
RS.close();
Stmt.close();
Conn.close();
}
catch (SQLException E) {
out.println("SQLException: " + E.getMessage());
out.println("SQLState: " + E.getSQLState());
out.println("VendorError: " + E.getErrorCode());
}
out.println("</body></html>");
}
public String getServletInfo() {
return "Create a page that says <i>Hello World</i> and send it back";
}
}
2011年9月12日 星期一
2011年1月9日 星期日
oracle multiple instance
oracle啟動順序為:監聽器→資料庫→資料庫控制。
關閉相反為:資料庫控制→資料庫→監聽器。
啟動
$lsnrctl start
$export ORACLE_SID=TEST
$echo $ORACLE_SID
$sqlplus / as sysdba
SQL>startup
SQL>exit
$emctl start dbconsole
關閉
$emctl stop dbconsole
$export ORACLE_SID=TEST
$echo $ORACLE_SID
$sqlplus / as sysdba
SQL>shutdown immediate
SQL>exit
$lsnrctl stop
可在監聽器、orcl資料庫、資料庫控制啟動狀態下,直接開啟一個TEST的instance
開機啟動
/etc/sysconfig/oracle
START_ORACLE_DB_LISTENER="yes"
START_ORACLE_DB="yes"
START_ORACLE_DB_EMANAGER="yes"
/etc/oratab
orcl:/opt/oracle/product/11gR2/db:Y
TEST:/opt/oracle/product/11gR2/db:Y
Running Multiple Instances
To run multiple instances, ensure that you have already created each instance. You then run multiple instances by starting each of the instances using SQL*Plus.
To run multiple instances:
1. Ensure that you have already created each instance.
2. Set the ORACLE_SID configuration parameter at the MS-DOS command prompt to the SID for each instance you want to run:
C:\> SET ORACLE_SID=SID
where SID is the name of the Oracle8i database instance.
3. Start SQL*Plus:
C:\> SQLPLUS
4. Connect as INTERNAL:
SQL> CONNECT INTERNAL
5. Start up the database with the new instance:
SQL> STARTUP PFILE=ORACLE_BASE\ADMIN\DB_NAME\PFILE\INIT.ORA
where ORACLE_BASE is C:\ORACLE by default (unless you changed it during installation) and DB_NAME is the name of the instance.
關閉相反為:資料庫控制→資料庫→監聽器。
啟動
$lsnrctl start
$export ORACLE_SID=TEST
$echo $ORACLE_SID
$sqlplus / as sysdba
SQL>startup
SQL>exit
$emctl start dbconsole
關閉
$emctl stop dbconsole
$export ORACLE_SID=TEST
$echo $ORACLE_SID
$sqlplus / as sysdba
SQL>shutdown immediate
SQL>exit
$lsnrctl stop
可在監聽器、orcl資料庫、資料庫控制啟動狀態下,直接開啟一個TEST的instance
開機啟動
/etc/sysconfig/oracle
START_ORACLE_DB_LISTENER="yes"
START_ORACLE_DB="yes"
START_ORACLE_DB_EMANAGER="yes"
/etc/oratab
orcl:/opt/oracle/product/11gR2/db:Y
TEST:/opt/oracle/product/11gR2/db:Y
Running Multiple Instances
To run multiple instances, ensure that you have already created each instance. You then run multiple instances by starting each of the instances using SQL*Plus.
To run multiple instances:
1. Ensure that you have already created each instance.
2. Set the ORACLE_SID configuration parameter at the MS-DOS command prompt to the SID for each instance you want to run:
C:\> SET ORACLE_SID=SID
where SID is the name of the Oracle8i database instance.
3. Start SQL*Plus:
C:\> SQLPLUS
4. Connect as INTERNAL:
SQL> CONNECT INTERNAL
5. Start up the database with the new instance:
SQL> STARTUP PFILE=ORACLE_BASE\ADMIN\DB_NAME\PFILE\INIT.ORA
where ORACLE_BASE is C:\ORACLE by default (unless you changed it during installation) and DB_NAME is the name of the instance.
訂閱:
文章 (Atom)