weblogic7自己有JDK,不用配置;
把你用的JSP文件放到:盘符+
/bea/wlserver6.1/config/mydomain/applications/DefaultWebApp目录下就可运行,不过应该先把weblogic7服务器启动起来;
使用SQL SERVER可以有几种方式,最简单的是在JSP页面中嵌入JDBC的调用代码,如:<%
String DriverName="sun.jdbc.odbc.JdbcOdbcDriver";
Class.forName(DriverName);
Connection cn=DriverManager.getConnection("Jdbc
dbc:bookstore","sa","goodat");
Statement stmt=cn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
%>
在WEBLOGIC中还有其它方式,我把我知道的经过验证的代码依次贴出来了:
<%@ page contentType="text/html;
charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<%@page import="java.util.*"%>
<html>
<head>
<title>用JDBC:ODBC获取池连接</title>
<meta http-equiv="Content-Type" content="text/html;
charset=gb2312">
</head>
<body>
<%
String driverName="sun.jdbc.odbc.JdbcOdbcDriver";
Class.forName(driverName);
String driverURL="jdbc
dbc:bookstore";
Connection cn=DriverManager.getConnection(driverURL,"sa","goodat");
//另一种连接方式
//String driverURL="jdbc:weblogic
ool:JdbcOdbc";
//Connection cn=myDriver.connect(driverURL,null);
Statement stmt=cn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
ResultSet rs=stmt.executeQuery("select * from gl_client_info");
while(rs.next()){
%>
<table width="45%" border="1">
<tr>
<td><%=rs.getString("client_name")%></td>
<td><%=rs.getString("client_sex")%></td>
</tr>
</table>
<%
}
rs.close();
stmt.close();
cn.close();
%>
</body>
</html>
<%@ page contentType="text/html;
charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<%@page import="javax.naming.*"%>
<html>
<head>
<title>通过JNDI查找数据源连接</title>
<meta http-equiv="Content-Type" content="text/html;
charset=gb2312">
</head>
<body>
<%
javax.sql.DataSource myDataSource=null;
try{
Context myContext=new InitialContext();
myDataSource=(javax.sql.DataSource)myContext.lookup("JdbcOdbcDS");
try{
Connection cn=myDataSource.getConnection();
Statement stmt=cn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
ResultSet rs=stmt.executeQuery("select * from gl_client_info");
while(rs.next()){
%>
<table width="45%" border="1">
<tr>
<td><%=rs.getString("client_name")%></td>
<td><%=rs.getString("client_sex")%></td>
</tr>
</table>
<%
}
rs.close();
stmt.close();
cn.close();
}catch(SQLException e){
e.toString();
}
}catch(NamingException e){
e.toString();
}
%>
</body>
</html>
<%@ page contentType="text/html;
charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<%@page import="javax.naming.*"%>
<html>
<head>
<title>通过JNDI查找多池连接的数据源连接</title>
<meta http-equiv="Content-Type" content="text/html;
charset=gb2312">
</head>
<body>
<%
javax.sql.DataSource myDataSource=null;
try{
Context myContext=new InitialContext();
myDataSource=(javax.sql.DataSource)myContext.lookup("MultiPoolDS");
try{
Connection cn=myDataSource.getConnection();
Statement stmt=cn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
ResultSet rs=stmt.executeQuery("select * from gl_client_info");
while(rs.next()){
%>
<table width="45%" border="1">
<tr>
<td><%=rs.getString("client_name")%></td>
<td><%=rs.getString("client_sex")%></td>
</tr>
</table>
<%
}
rs.close();
stmt.close();
cn.close();
}catch(SQLException e){
e.toString();
}
}catch(NamingException e){
e.toString();
}
%>
</body>
</html>
<%@ page contentType="text/html;
charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<%@page import="java.util.*"%>
<html>
<head>
<title>从WEBLOGIC池驱动程序获取池连接</title>
<meta http-equiv="Content-Type" content="text/html;
charset=gb2312">
</head>
<body>
<%
String driverName="weblogic.jdbc.pool.Driver";
Driver myDriver=(Driver)Class.forName(driverName).newInstance();
String driverURL="jdbc:weblogic
ool";
Properties myProperties=new Properties();
myProperties.put("connectionPoolID","JdbcOdbc");
Connection cn=myDriver.connect(driverURL,myProperties);
//另一种连接方式
//String driverURL="jdbc:weblogic
ool:JdbcOdbc";
//Connection cn=myDriver.connect(driverURL,null);
Statement stmt=cn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
ResultSet rs=stmt.executeQuery("select * from gl_client_info");
while(rs.next()){
%>
<table width="45%" border="1">
<tr>
<td><%=rs.getString("client_name")%></td>
<td><%=rs.getString("client_sex")%></td>
</tr>
</table>
<%
}
rs.close();
stmt.close();
cn.close();
%>
</body>
</html>
<%@ page contentType="text/html;
charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<%@page import="java.util.*"%>
<html>
<head>
<title>从WEBLOGIC的多连接池驱动程序获取池连接</title>
<meta http-equiv="Content-Type" content="text/html;
charset=gb2312">
</head>
<body>
<%
String driverName="weblogic.jdbc.pool.Driver";
Driver myDriver=(Driver)Class.forName(driverName).newInstance();
String driverURL="jdbc:weblogic
ool";
Properties myProperties=new Properties();
myProperties.put("connectionPoolID","MyJDBC MultiPool");
Connection cn=myDriver.connect(driverURL,myProperties);
//另一种连接方式
//String driverURL="jdbc:weblogic
ool:JdbcOdbc";
//Connection cn=myDriver.connect(driverURL,null);
Statement stmt=cn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
ResultSet rs=stmt.executeQuery("select * from gl_client_info");
while(rs.next()){
%>
<table width="45%" border="1">
<tr>
<td><%=rs.getString("client_name")%></td>
<td><%=rs.getString("client_sex")%></td>
</tr>
</table>
<%
}
rs.close();
stmt.close();
cn.close();
%>
</body>
</html>
请参考。