將Ubuntu 12.10的Java換成Oracle的Java
指令如下:
sudo apt-get purge openjdk* #移除OpenJDK
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer
sudo apt-get purge openjdk* #移除OpenJDK
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer
<%@ page contentType="text/html;charset=utf-8" language="java" import="java.sql.*, oracle.jdbc.*"%>
Oracle連結測試<P>
<%
ResultSet rs = null;
String oracleURL="jdbc:oracle:thin:@資料庫位址:SID";
String oracleUser="帳號";
String oraclePass="密碼";
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 會員");
rs.last();
out.print("本網站有"+rs.getRow()+"位會員");
rs.close();
stmt.close();
conn.close();
}catch (SQLException ce){
System.out.print(ce);
}
%>
<?xml version="1.0" encoding="utf-"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<resource-ref>
<description>Oracle Datasource example</description>
<res-ref-name>jdbc/myoracle</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
<?xml version='1.0' encoding='utf-8'?>
<Context>
<WatchedResource>./WEB-INF/web.xml</WatchedResource>
<Resource name="jdbc/myoracle" auth="Container"
factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory"
type="javax.sql.DataSource" driverClassName="oracle.jdbc.OracleDriver"
url="jdbc:oracle:thin:@資料庫位址:Port:SID"
username="帳號" password="密碼" maxActive="20" maxIdle="10"
maxWait="-1"/>
</Context>
<GlobalNamingResources>
<!-- Editable user database that can also be used by
UserDatabaseRealm to authenticate users -->
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
<Resource name="jdbc/myoracle" auth="Container"
factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory"
type="javax.sql.DataSource" driverClassName="oracle.jdbc.OracleDriver"
url="jdbc:oracle:thin:@資料庫位址:Port:SID"
username="帳號" password="密碼" maxActive="20" maxIdle="10"
maxWait="-1"/>
</GlobalNamingResources>