JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » JDBC/SQL討論區  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to topicthreaded modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 快速測試 Tomcat + Oracle 9i + JSP [精華]
anthonycs



版主

發文: 1195
積分: 6
於 2003-09-06 23:48 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我的環境是Windows 2000, 不過相同觀念在Linux下應該可以適用,
有機會我會驗證看看, 再post上來

版本:Tomcat 4.1.X , Oracle 9.2.0.1.0 , J2SDK1.4.2_01

1.
首先安裝JDK 1.4.2_01 , http://java.sun.com/j2se/
設定 JAVA_HOME=C:\j2sdk1.4.2_01

2.
接著安裝Oracle9i, 安裝完成之後先更改XML Database的參數
因為XML Database的Http Server預設使用port 8080, 會和Tomcat相衝
建議更改為8081, 參考這兩張圖
http://home.pchome.com.tw/service/anthonycs/image/oracle04.gif
http://home.pchome.com.tw/service/anthonycs/image/oracle05.gif

3.
接著安裝Tomcat, 使用上面安裝的 j2sdk1.4.2_01作為Tomcat的Virtual Machine
如果使用zip版本的 Tomcat , 解壓縮之後在系統變數增加 CATALINA_HOME
設定參考 此篇文章

4.
下載Oracle JDBC Driver http://otn.oracle.com/software/tech/java/sqlj_jdbc/content.html
注意 :JDK, Tomcat, Oracle JDBC Driver 三者要協調好
以我的例子來說 , Tomcat是設定 j2sdk1.4.2_01 為使用的jdk
因此在選擇 Oracle JDBC Driver 就以 j2sdk1.4.2_01 來作選擇
依照j2sdk1.4.2_01, Oracle 9.2.0.1.0的版本, 是三個檔案 ocrs12.zip ojdbc14.jar ojdbc14_g.jar
將下載的檔案放置到 \webapps\examples\WEB-INF\lib\ 裡面
重新啟動Tomcat服務

5.
設定Oracle資料庫帳號供程式使用 (如果您已經熟悉帳號管理,請跳過此步驟)
這邊以預設資料庫的HR為範例, 參考下面三張圖 , 畫面較大, 抓下來欣賞比較好
http://home.pchome.com.tw/service/anthonycs/image/oracle01.gif
http://home.pchome.com.tw/service/anthonycs/image/oracle02.gif
http://home.pchome.com.tw/service/anthonycs/image/oracle03.gif

6.
寫JSP網頁, 參考以下
藍色部分依照您的Oracle主機設定而異 (IP, SID,密碼)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<%@ page contentType="text/html;charset=Big5" language="java" import="java.sql.*, oracle.jdbc.*"%>
<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY>
 
    測試OracleDriver<P>
<%
    ResultSet rs = null;
    String oracleURL="jdbc:oracle:thin:@Oracle主機ip:1521:SID";
    String oracleUser="HR"; 
    String oraclePass="xxxx";
    try {
            DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
    }catch (SQLException e){
            out.print("Driver Error");
    }
    try {
            Connection conn = DriverManager.getConnection(oracleURL,oracleUser,oraclePass);
            Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
            rs=stmt.executeQuery("select * from EMPLOYEES");
            rs.last();
            out.print("HR資料庫中有員工"+rs.getRow()+"個");
            rs.close();
            stmt.close();
            conn.close();
    }catch (SQLException ce){
            System.out.print(ce);
    }
 
%>
 
</BODY>
</HTML>


將JSP檔案存成test.jsp放在 \webapps\examples\ 裡面
測試結果 http://localhost:8080/examples/test.jsp

(很懶惰所以把Driver還有jsp都放在examples底下,如果您會部署webapp請自行更改)

Finish !!


anthonycs edited on 2004-09-16 23:55
reply to postreply to post
作者 Re:快速測試 Tomcat + Oracle 9i + JSP [Re:anthonycs]
javatim

提姆



發文: 13
積分: 0
於 2004-02-05 15:23 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
ORACLE不是要在JAVA SDK安裝前先灌好嗎?
bowwow


reply to postreply to post
作者 Re:快速測試 Tomcat + Oracle 9i + JSP [Re:anthonycs]
pongpong





發文: 5
積分: 0
於 2004-05-02 01:32 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我的tomcat沒有這個路徑
\webapps\examples\WEB-INF\lib\

我的是5.0.19
我的路徑是
C:\Program Files\Apache Software Foundation\tomcat5\webapps\
之後就沒有啦

我應該怎麼辦??


reply to postreply to post
作者 Re:快速測試 Tomcat + Oracle 9i + JSP [Re:anthonycs]
pongpong





發文: 5
積分: 0
於 2004-05-02 02:15 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
請問在Oracle enterprise manager cousole standaloe中

database內的帳戶是否有預設username及密碼??(database connect information)
因為我安裝時設定的密碼進不去


reply to postreply to post
作者 Re:快速測試 Tomcat + Oracle 9i + JSP [Re:anthonycs]
s813141





發文: 13
積分: 0
於 2004-05-07 10:49 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
預設帳號密碼
internal/oracle
sys/change_on_install
system/manager
scott/tiger
sysman/oem_temp


reply to postreply to post
作者 Re:快速測試 Tomcat + Oracle 9i + JSP [Re:pongpong]
anthonycs



版主

發文: 1195
積分: 6
於 2004-05-19 01:12 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
pongpong wrote:
我的tomcat沒有這個路徑
\webapps\examples\WEB-INF\lib\


5.0 的 Tomcat , 將我寫的 examples 對照到 jsp-examples

也就是將 Driver 放置在 \webapps\jsp-examples\WEB-INF\lib\

將 jsp檔案 放置在\webapps\jsp-examples\

當然這是很偷懶的寫法 , 如果您自己學習部署WebApp , 就不會有此問題了 Wink


reply to postreply to post
新手請維持互動討論精神, 請看良好的 討論示範
作者 Re:快速測試 Tomcat + Oracle 9i + JSP [Re:anthonycs]
tocade





發文: 4
積分: 0
於 2004-06-02 10:22 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
那如果放在 tomcat_dir\shared\lib裡,有什麼不同嗎??

reply to postreply to post
作者 Re:快速測試 Tomcat + Oracle 9i + JSP [Re:tocade]
snpshu

Norman

版主

發文: 1073
積分: 5
於 2004-06-02 11:09 user profilesend a private message to usersend email to snpshureply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
tocade wrote:
那如果放在 tomcat_dir\shared\lib裡,有什麼不同嗎??


給全部的webapps ? 但是移植設定不方便..


reply to postreply to post
作者 Re:快速測試 Tomcat + Oracle 9i + JSP [Re:anthonycs]
tocade





發文: 4
積分: 0
於 2004-06-03 10:27 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
不好意思,我想請問一下,所謂的移植設定不方便,是那裡不方便呢??

reply to postreply to post
作者 Re:快速測試 Tomcat + Oracle 9i + JSP [Re:tocade]
tomhawk





發文: 3
積分: 0
於 2004-06-07 19:14 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
tocade wrote:
不好意思,我想請問一下,所謂的移植設定不方便,是那裡不方便呢??

用.war檔包裝web app時, 只適合把jar檔放在WEB-INF/lib之下.
如果放在tomcat的目錄下, 必須用其他方式達成.


reply to postreply to post
目前沒有簽名檔...
作者 Re:快速測試 Tomcat + Oracle 9i + JSP [Re:anthonycs]
peanus





發文: 18
積分: 0
於 2004-08-23 15:56 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
您好,我想請問一下。
我照著anthonycs大大的文章,做好了測試的工作,
出現的結果只在ie顯示出「測試Oracle Driver」這麼一行字,
請問這樣是正確的結果嗎?


reply to postreply to post
最菜的新手
作者 Re:快速測試 Tomcat + Oracle 9i + JSP [Re:peanus]
anthonychen

外線交給我

版主

發文: 2033
積分: 8
於 2004-08-23 16:30 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
peanus wrote:
您好,我想請問一下。
我照著anthonycs大大的文章,做好了測試的工作,
出現的結果只在ie顯示出「測試Oracle Driver」這麼一行字,
請問這樣是正確的結果嗎?

應該不正確,請確認一下 tomcat command line 視窗有沒有錯誤訊息。

照原來的範例程式,應該會出現 "HR資料庫中有員工 ? 個" 的訊息 (? 為數字)


reply to postreply to post
作者 Re:快速測試 Tomcat + Oracle 9i + JSP [Re:anthonycs]
peanus





發文: 18
積分: 0
於 2004-10-07 13:22 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
對不起,我想請教一個問題,
我的試這個測試的環境是:windows 2000
tomcat 5.0.16
j2sdk1.4.2_03

試出來的結果還是只有那一行「測試OracleDriver」
沒有錯誤訊息,
會不會是因為版本的問題,所以抓不到資料?


reply to postreply to post
最菜的新手
作者 Re:快速測試 Tomcat + Oracle 9i + JSP [Re:anthonycs]
peanus





發文: 18
積分: 0
於 2004-10-08 01:23 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
抱歉,我已經找出問題了,
全是自已的不小心,把密碼設錯了,所以才沒抓到資料庫裡的資料 = =a


reply to postreply to post
最菜的新手
作者 Re:快速測試 Tomcat + Oracle 9i + JSP [Re:anthonycs]
AmyJao





發文: 3
積分: 0
於 2004-11-09 16:17 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
請教一下以下的問題
測試環境:windows xp + tomcat 5.0 + oracle 9.2 + jdk1.4.2_05
寫了一段程式碼去連結資料庫,一直出現找不到適合的driver,已至官方網站downlad了最近的jdbc driver
以下為錯誤訊息:
java.sql.SQLException: No suitable driver
請教各位高手,這是什麼原因呢??不懂耶!!Dead


reply to postreply to post
作者 Re:快速測試 Tomcat + Oracle 9i + JSP [Re:AmyJao]
morchory



管理者

發文: 167
積分: 0
於 2004-11-09 17:12 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
AmyJao wrote:
請教一下以下的問題
測試環境:windows xp + tomcat 5.0 + oracle 9.2 + jdk1.4.2_05
寫了一段程式碼去連結資料庫,一直出現找不到適合的driver,已至官方網站downlad了最近的jdbc driver
以下為錯誤訊息:
java.sql.SQLException: No suitable driver
請教各位高手,這是什麼原因呢??不懂耶!!Dead


全文檢索: No suitable driver


reply to postreply to post
作者 Re:快速測試 Tomcat + Oracle 9i + JSP [Re:anthonycs]
peanus





發文: 18
積分: 0
於 2004-12-31 18:26 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
請問一下,以下的程式是否能正確的抓出資料庫裡欄位的值?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<%@ page contentType = "text/html;charset = big5" language="java" 
 
import="java.sql.*,oracle.jdbc.*"%>
<html>
<head>
<title>jdbc test</title>
</head>
<body>
<%
  ResultSet rs = null;
  String oracleURL="jdbc:oracle:thin: @140.131.7.72:1521:ora057";
  String oracleUser="SCOTT";
  String oraclePass="tiger";
  try{
  DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
      }catch (SQLException e){
        out.print("Driver ERROR");
  }
  try{
  Connection 
 
conn=DriverManager.getConnection(oracleURL,oracleUser,oraclePass);
  Statement stmt = 
 
conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_
 
UPDATABLE);
  rs = stmt.executeQuery("select last_name from employees where 
 
last_name LIKE 'K%'");
  //rs.last();
  while(rs.next())
  {
      out.println(rs.getString("last_name")+"<br>");
  }
  out.print(rs.getString());
  rs.close();
  stmt.close();
  conn.close();
  }catch(SQLException ce){
    System.out.print(ce);
  }
%>
</body>
</html>


peanus edited on 2005-09-07 10:53
reply to postreply to post
最菜的新手
作者 Re:快速測試 Tomcat + Oracle 9i + JSP [Re:anthonycs]
小桃子





發文: 115
積分: 0
於 2005-02-17 11:41 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
你好..請問一下....
我的oracle9i是灌client版的...我後端還連接了一個oracle server

而我的問題是..我要修改我的xml database的port時...
卻不能修改.....
會出現"套用動態參數失敗.ORA-31050:存取被拒
ORA-06512:在XDB.DBMS_XDB.line 168
OPA_06512:在line1"
的訊息......
我以為是我灌限不夠..
所以改用system/manager connect為SYSDBA 或SYSOPER進入..
都會顯示...."權限不足".....

請問這是什麼原因呢????


reply to postreply to post
作者 Re:快速測試 Tomcat + Oracle 9i + JSP [Re:anthonycs]
ahkalex





發文: 3
積分: 0
於 2005-03-15 21:33 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我的測試環境為:
os=windows2000,Tomcat 4.1 , Oracle 9.2.0.1.0 , J2SDK1.4.2_01
依照anthonycs 所敘述的步驟設定,試過多次仍出現錯誤訊息,請指點一下迷津,
感恩!!
============設定資料================
JAVA_HOME=C:\j2sdk1.4.2_01
TOMCAT_HOME=C:\Program Files\Apache Group\Tomcat 4.1
CLASSPATH=%TOMCAT_HOME%\common\lib\servlet.jar;%JAVA_HOME%\lib\tools.jar;%JAVA_HOME%\lib;%TOMCAT_HOME%\server\lib
PATH=%JAVA_HOME%\bin
============錯誤訊息================
org.apache.jasper.JasperException: java/sql/Savepoint
  at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:254)
  at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
  at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
  at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
  at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
  at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
  at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
  at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
  at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
  at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2422)
  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
  at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
  at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
  at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
  at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:163)
  at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
  at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
  at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
  at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
  at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
  at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
  at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
  at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:199)
  at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:828)
  at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:700)
  at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:584)
  at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
  at java.lang.Thread.run(Thread.java:484)

=============== END =================
迷惑的人~ 等待救援中....


reply to postreply to post
作者 Re:快速測試 Tomcat + Oracle 9i + JSP [Re:anthonycs]
antnio13





發文: 2
積分: 0
於 2006-02-13 17:31 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
好像是到JAVA原始碼對著行號找錯

很傷身 ^^


reply to postreply to post
» JWorld@TW »  JDBC/SQL討論區

reply to topicthreaded modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8