jsp连接oracle数据库
首先你要有tomcat,还要有oracle jdbc的jar档等环境.
第一步: 写JSP
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<html>
<body>
<%Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url="jdbc:oracle:thin:@(description=(address_list= (address=(host=10.10.10.103) (protocol=tcp)(port=1521))(address=(host=192.168.60.144)(protocol=tcp) (port=1521)) (load_balance=yes)(failover=yes))(connect_data=(service_name= oratest)))";
String user="test";
String password="test";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="select * from session_cmd where user_id = 'test'";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()) {%>
Your first segment :<%=rs.getString(1)%>
Your second segmet :<%=rs.getString(2)%>
<%}%>
<%out.print("DB connect successful, congrations");%>
<%rs.close();
stmt.close();
conn.close();
%>
</body>
</html>
第二步:
把$ORACLE_HOME\jdbc\lib下的classes12.jar拷贝到你的WEB-INF/lib下,
或者拷贝到JDK目录:jdk\jre\lib\ext下。
第三步:
把你的包放到tomcat/webapps下比如
/opt/tomcat/webapps/testdb ---- testdb就是你刚才做的JSP还有WEB-INF,其实WEB-INF里面只要lib下面放oracle JDBC 的jar档就行了.重启tomcat.
最后一步:
可以在IE上测试你是否能否连接DB.
相关文档:
移动表所在表空间:
alter table table_name(表名) move tablespace new_tablespace(新表空间)
用户拥有的存储过程:
select object_name from user_objects where object_type='PROCEDURE'; ......
不知道是不是驱动加载有问题,在MyEclipse中写了简单的数据库测试程序找不到驱动类,希望大虾能给予帮助,谢了。
严重: Servlet.service() for servlet jsp threw exception
java.lang.ClassNotFoundException: org.aspectj.lang.Signature
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClas ......
1.添加 host 块
每一个JSP虚拟主机有它自己的 host 块。每一个至少要定义id来指定虚拟主机的名字和一个root应用程序。一个 <root-directory>通常用来为主机定一个默认的web应用程序。
配置文件片段:
<server>
<host id='gryffindor.caucho.com'>
<root-directory>/home/www/gryf ......
1、创建表:
create table stud(
sid int,
sname varchar2(50)
)
并插入一条数据
&n ......