JAVA连接Oracle 9i代码
import java.sql.*;
class dbtest
{
public static void main(String args[]) throws SQLException
{
DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
Connection conn = DriverManager.getConnection
("jdbc:oracle:thin:@192.168.0.94:1521:ORAC","scott","tiger");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from dept");
while(rs.next())
{
System.out.println(rs.getString(1) +"----"+ rs.getString(2));
}
System.out.println("数据库操作成功,恭喜你");
rs.close();
stmt.close();
conn.close();
}
}
JSP连接Oracle 9i 示例
<%@ page contentType="text/html;charset=gb2312" language="java"%>
<%@ page import="java.sql.*"%>
<html>
<body>
<%Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url="jdbc:oracle:thin:@192.168.0.94:1521:orac";
String user="scott";
String password="tiger";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="select * from dept";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()) {%>
<%=rs.getString(1)%>----<%=rs.getString(2)%> <br>
<%}%>
<%out.print("数据库操作成功,恭喜你");%>
<%rs.close();
stmt.close();
conn.close();
%>
</body>
</html>
注:192.168.0.94为主机IP地址,也可以写你的主机名,ORAC为你的数据库的SID
即服务名.