可是如何在JSP里进行调用呀?
12 个解决方案
#1
不会吧
没人会?
没人会?
#2
这篇文章在哪?还得先找文章看看!
#3
http://www.csdn.net/develop/article/14/14181.shtm
这就是那篇文章,写的很好
可是我不用JBUILDER
我只需要在WEBLOGIC里配置好SQL SERVER
然后再在JSP里调用就行了
请教如何调用呀
这就是那篇文章,写的很好
可是我不用JBUILDER
我只需要在WEBLOGIC里配置好SQL SERVER
然后再在JSP里调用就行了
请教如何调用呀
#4
按照他写的代码写个Bean,然后在JSP中调用这个Bean,然后创建一个连接,就Ok了!
我这里没有SQL Server,没办法测试,抛砖引玉,你可以自己再研究一下。
import java.sql.*;
import javax.sql.*;
import javax.naming.*;
import java.io.*;
import java.util.*;
public class Database
{
String DSName="SQLServer";
DataSource ds=null;
Connection Connt;
//========================构造函数========================//
public Database()
{
System.out.println("Database Bean has been Contructured!");
}
//========================建立数据库连接========================//
public Connection GetConnection() throws SQLException
{
Hashtable ht = new Hashtable();
ht.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
ht.put(Context.PROVIDER_URL,"t3://localhost:7001");
try
{
Context ctx = (Context) new InitialContext().lookup("");
ds = (DataSource) ctx.lookup(DSName);
Connt = ds.getConnection("system","12345678");//此处是WebLogic7的域用户和密码
}catch(javax.naming.NamingException ne)
{
System.err.println("Database-->getConnection Error:" + ne.getMessage());
Connt = null;
}
return Connt;
}
我这里没有SQL Server,没办法测试,抛砖引玉,你可以自己再研究一下。
import java.sql.*;
import javax.sql.*;
import javax.naming.*;
import java.io.*;
import java.util.*;
public class Database
{
String DSName="SQLServer";
DataSource ds=null;
Connection Connt;
//========================构造函数========================//
public Database()
{
System.out.println("Database Bean has been Contructured!");
}
//========================建立数据库连接========================//
public Connection GetConnection() throws SQLException
{
Hashtable ht = new Hashtable();
ht.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
ht.put(Context.PROVIDER_URL,"t3://localhost:7001");
try
{
Context ctx = (Context) new InitialContext().lookup("");
ds = (DataSource) ctx.lookup(DSName);
Connt = ds.getConnection("system","12345678");//此处是WebLogic7的域用户和密码
}catch(javax.naming.NamingException ne)
{
System.err.println("Database-->getConnection Error:" + ne.getMessage());
Connt = null;
}
return Connt;
}
#5
直接在JSP里调用连接池不行吗
我刚学JAVA
怎么建BEAN,怎么发布到WEBLOGIC里都不会
没有别的方法了吗
我刚学JAVA
怎么建BEAN,怎么发布到WEBLOGIC里都不会
没有别的方法了吗
#6
mygod
#7
再顶呀.
急呀...
急呀...
#8
去看一个例子,保准你就会了:http://www.aspjsp.net/lv8.asp?id=74
#9
我的WEBLOGIC呀..
#10
顶
#11
我说,你没看例子吗,确实解决了你的问题。数据源是从ODBC配置的,不用管WebLogic。
#12
请给分吧。
1、先从微软的网站上下载MS SQL SERVER 2000 JDBC驱动程序包,并拷贝至一目录下,然后在WEBLOGIC的环境配置文件setWLSEnv.cmd中加入,set CLASSPATH=%JAVA_HOME%\lib\tools.jar;%WL_HOME%\server\lib\weblogic_sp.jar;%WL_HOME%\server\lib\weblogic.jar;%WL_HOME%\server\lib\webservices.jar;%WL_HOME%\server\lib\mssqlserver.jar;%WL_HOME%\server\lib\msbase.jar;%WL_HOME%\server\lib\msutil.jar;%CLASSPATH%
其中以下是MS SQL SERVER JDBC 驱动程序包:
mssqlserver.jar
msbase.jar
msutil.jar
2、启动WEBLOGIC
3、编写读取数据库的JSP文件,下面给你一个例子,拷贝至D:\bea\user_projects\mydomain\applications\DefaultWebApp,
然后在浏览器中输入http://localhost:7001/test.jsp即可
//TEST.JSP
<!doctype html public "-//w3c//dtd html 3.2//en">
<html>
<head>
<%@ page contentType="text/html;charset=gb2312" %>
<title>Fields List</title>
</head>
<body>
<p><img border="0" src="file:///D:/bea/config/mydomain/applications/DefaultWebApp_myserver/images/redarrow.gif" width="11" height="11"><img border="0" src="file:///D:/bea/config/mydomain/applications/DefaultWebApp_myserver/images/built_bea_web.gif" width="100" height="36"></p>
<p>
<p>
<font size="5" color="#FF00FF"><span style="background-color: #CCCC00">
<marquee scrolldelay="70">WELCOME TO YOU...</marquee>
</p>
<%@ page import="
java.sql.*,java.io.*,java.util.Vector
" %>
<%
//String url = "jdbc:weblogic:mssqlserver4:oydms@ljtcm:1433";
String url = "jdbc:microsoft:sqlserver://mainserver:1433;DatabaseName=test;user=sa;password=sa";
//String url = "jdbc:odbc:MQIS";
//String user = "sa";
//String password = "sa";
Connection conn=null;
Statement stm=null;
ResultSet rs=null;
try {
String sql = "select * from test where name='9999'";
//Class.forName("weblogic.jdbc.mssqlserver4.Driver").newInstance();
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
//Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
//Class.forName("weblogic.jdbc.pool.Driver").newInstance();
conn = DriverManager.getConnection(url);
stm = conn.createStatement();
rs = stm.executeQuery(sql);
while(rs.next())
{
out.println(rs.getString(1)+" "+rs.getString(2)+" "+rs.getString(3));
}
} catch (Exception sqle) {
out.print("Sorry, the database is not available.first catch");
out.print("Exception: " + sqle);
} finally {
if(conn != null)
try {
conn.close();
} catch(Exception sqle) {
out.print("Sorry, the database is not closed.last catch");
out.print("Exception: " + sqle);
}
}
%>
</span></font></p>
<p>
</font>
</body>
</html>
1、先从微软的网站上下载MS SQL SERVER 2000 JDBC驱动程序包,并拷贝至一目录下,然后在WEBLOGIC的环境配置文件setWLSEnv.cmd中加入,set CLASSPATH=%JAVA_HOME%\lib\tools.jar;%WL_HOME%\server\lib\weblogic_sp.jar;%WL_HOME%\server\lib\weblogic.jar;%WL_HOME%\server\lib\webservices.jar;%WL_HOME%\server\lib\mssqlserver.jar;%WL_HOME%\server\lib\msbase.jar;%WL_HOME%\server\lib\msutil.jar;%CLASSPATH%
其中以下是MS SQL SERVER JDBC 驱动程序包:
mssqlserver.jar
msbase.jar
msutil.jar
2、启动WEBLOGIC
3、编写读取数据库的JSP文件,下面给你一个例子,拷贝至D:\bea\user_projects\mydomain\applications\DefaultWebApp,
然后在浏览器中输入http://localhost:7001/test.jsp即可
//TEST.JSP
<!doctype html public "-//w3c//dtd html 3.2//en">
<html>
<head>
<%@ page contentType="text/html;charset=gb2312" %>
<title>Fields List</title>
</head>
<body>
<p><img border="0" src="file:///D:/bea/config/mydomain/applications/DefaultWebApp_myserver/images/redarrow.gif" width="11" height="11"><img border="0" src="file:///D:/bea/config/mydomain/applications/DefaultWebApp_myserver/images/built_bea_web.gif" width="100" height="36"></p>
<p>
<p>
<font size="5" color="#FF00FF"><span style="background-color: #CCCC00">
<marquee scrolldelay="70">WELCOME TO YOU...</marquee>
</p>
<%@ page import="
java.sql.*,java.io.*,java.util.Vector
" %>
<%
//String url = "jdbc:weblogic:mssqlserver4:oydms@ljtcm:1433";
String url = "jdbc:microsoft:sqlserver://mainserver:1433;DatabaseName=test;user=sa;password=sa";
//String url = "jdbc:odbc:MQIS";
//String user = "sa";
//String password = "sa";
Connection conn=null;
Statement stm=null;
ResultSet rs=null;
try {
String sql = "select * from test where name='9999'";
//Class.forName("weblogic.jdbc.mssqlserver4.Driver").newInstance();
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
//Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
//Class.forName("weblogic.jdbc.pool.Driver").newInstance();
conn = DriverManager.getConnection(url);
stm = conn.createStatement();
rs = stm.executeQuery(sql);
while(rs.next())
{
out.println(rs.getString(1)+" "+rs.getString(2)+" "+rs.getString(3));
}
} catch (Exception sqle) {
out.print("Sorry, the database is not available.first catch");
out.print("Exception: " + sqle);
} finally {
if(conn != null)
try {
conn.close();
} catch(Exception sqle) {
out.print("Sorry, the database is not closed.last catch");
out.print("Exception: " + sqle);
}
}
%>
</span></font></p>
<p>
</font>
</body>
</html>
#1
不会吧
没人会?
没人会?
#2
这篇文章在哪?还得先找文章看看!
#3
http://www.csdn.net/develop/article/14/14181.shtm
这就是那篇文章,写的很好
可是我不用JBUILDER
我只需要在WEBLOGIC里配置好SQL SERVER
然后再在JSP里调用就行了
请教如何调用呀
这就是那篇文章,写的很好
可是我不用JBUILDER
我只需要在WEBLOGIC里配置好SQL SERVER
然后再在JSP里调用就行了
请教如何调用呀
#4
按照他写的代码写个Bean,然后在JSP中调用这个Bean,然后创建一个连接,就Ok了!
我这里没有SQL Server,没办法测试,抛砖引玉,你可以自己再研究一下。
import java.sql.*;
import javax.sql.*;
import javax.naming.*;
import java.io.*;
import java.util.*;
public class Database
{
String DSName="SQLServer";
DataSource ds=null;
Connection Connt;
//========================构造函数========================//
public Database()
{
System.out.println("Database Bean has been Contructured!");
}
//========================建立数据库连接========================//
public Connection GetConnection() throws SQLException
{
Hashtable ht = new Hashtable();
ht.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
ht.put(Context.PROVIDER_URL,"t3://localhost:7001");
try
{
Context ctx = (Context) new InitialContext().lookup("");
ds = (DataSource) ctx.lookup(DSName);
Connt = ds.getConnection("system","12345678");//此处是WebLogic7的域用户和密码
}catch(javax.naming.NamingException ne)
{
System.err.println("Database-->getConnection Error:" + ne.getMessage());
Connt = null;
}
return Connt;
}
我这里没有SQL Server,没办法测试,抛砖引玉,你可以自己再研究一下。
import java.sql.*;
import javax.sql.*;
import javax.naming.*;
import java.io.*;
import java.util.*;
public class Database
{
String DSName="SQLServer";
DataSource ds=null;
Connection Connt;
//========================构造函数========================//
public Database()
{
System.out.println("Database Bean has been Contructured!");
}
//========================建立数据库连接========================//
public Connection GetConnection() throws SQLException
{
Hashtable ht = new Hashtable();
ht.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
ht.put(Context.PROVIDER_URL,"t3://localhost:7001");
try
{
Context ctx = (Context) new InitialContext().lookup("");
ds = (DataSource) ctx.lookup(DSName);
Connt = ds.getConnection("system","12345678");//此处是WebLogic7的域用户和密码
}catch(javax.naming.NamingException ne)
{
System.err.println("Database-->getConnection Error:" + ne.getMessage());
Connt = null;
}
return Connt;
}
#5
直接在JSP里调用连接池不行吗
我刚学JAVA
怎么建BEAN,怎么发布到WEBLOGIC里都不会
没有别的方法了吗
我刚学JAVA
怎么建BEAN,怎么发布到WEBLOGIC里都不会
没有别的方法了吗
#6
mygod
#7
再顶呀.
急呀...
急呀...
#8
去看一个例子,保准你就会了:http://www.aspjsp.net/lv8.asp?id=74
#9
我的WEBLOGIC呀..
#10
顶
#11
我说,你没看例子吗,确实解决了你的问题。数据源是从ODBC配置的,不用管WebLogic。
#12
请给分吧。
1、先从微软的网站上下载MS SQL SERVER 2000 JDBC驱动程序包,并拷贝至一目录下,然后在WEBLOGIC的环境配置文件setWLSEnv.cmd中加入,set CLASSPATH=%JAVA_HOME%\lib\tools.jar;%WL_HOME%\server\lib\weblogic_sp.jar;%WL_HOME%\server\lib\weblogic.jar;%WL_HOME%\server\lib\webservices.jar;%WL_HOME%\server\lib\mssqlserver.jar;%WL_HOME%\server\lib\msbase.jar;%WL_HOME%\server\lib\msutil.jar;%CLASSPATH%
其中以下是MS SQL SERVER JDBC 驱动程序包:
mssqlserver.jar
msbase.jar
msutil.jar
2、启动WEBLOGIC
3、编写读取数据库的JSP文件,下面给你一个例子,拷贝至D:\bea\user_projects\mydomain\applications\DefaultWebApp,
然后在浏览器中输入http://localhost:7001/test.jsp即可
//TEST.JSP
<!doctype html public "-//w3c//dtd html 3.2//en">
<html>
<head>
<%@ page contentType="text/html;charset=gb2312" %>
<title>Fields List</title>
</head>
<body>
<p><img border="0" src="file:///D:/bea/config/mydomain/applications/DefaultWebApp_myserver/images/redarrow.gif" width="11" height="11"><img border="0" src="file:///D:/bea/config/mydomain/applications/DefaultWebApp_myserver/images/built_bea_web.gif" width="100" height="36"></p>
<p>
<p>
<font size="5" color="#FF00FF"><span style="background-color: #CCCC00">
<marquee scrolldelay="70">WELCOME TO YOU...</marquee>
</p>
<%@ page import="
java.sql.*,java.io.*,java.util.Vector
" %>
<%
//String url = "jdbc:weblogic:mssqlserver4:oydms@ljtcm:1433";
String url = "jdbc:microsoft:sqlserver://mainserver:1433;DatabaseName=test;user=sa;password=sa";
//String url = "jdbc:odbc:MQIS";
//String user = "sa";
//String password = "sa";
Connection conn=null;
Statement stm=null;
ResultSet rs=null;
try {
String sql = "select * from test where name='9999'";
//Class.forName("weblogic.jdbc.mssqlserver4.Driver").newInstance();
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
//Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
//Class.forName("weblogic.jdbc.pool.Driver").newInstance();
conn = DriverManager.getConnection(url);
stm = conn.createStatement();
rs = stm.executeQuery(sql);
while(rs.next())
{
out.println(rs.getString(1)+" "+rs.getString(2)+" "+rs.getString(3));
}
} catch (Exception sqle) {
out.print("Sorry, the database is not available.first catch");
out.print("Exception: " + sqle);
} finally {
if(conn != null)
try {
conn.close();
} catch(Exception sqle) {
out.print("Sorry, the database is not closed.last catch");
out.print("Exception: " + sqle);
}
}
%>
</span></font></p>
<p>
</font>
</body>
</html>
1、先从微软的网站上下载MS SQL SERVER 2000 JDBC驱动程序包,并拷贝至一目录下,然后在WEBLOGIC的环境配置文件setWLSEnv.cmd中加入,set CLASSPATH=%JAVA_HOME%\lib\tools.jar;%WL_HOME%\server\lib\weblogic_sp.jar;%WL_HOME%\server\lib\weblogic.jar;%WL_HOME%\server\lib\webservices.jar;%WL_HOME%\server\lib\mssqlserver.jar;%WL_HOME%\server\lib\msbase.jar;%WL_HOME%\server\lib\msutil.jar;%CLASSPATH%
其中以下是MS SQL SERVER JDBC 驱动程序包:
mssqlserver.jar
msbase.jar
msutil.jar
2、启动WEBLOGIC
3、编写读取数据库的JSP文件,下面给你一个例子,拷贝至D:\bea\user_projects\mydomain\applications\DefaultWebApp,
然后在浏览器中输入http://localhost:7001/test.jsp即可
//TEST.JSP
<!doctype html public "-//w3c//dtd html 3.2//en">
<html>
<head>
<%@ page contentType="text/html;charset=gb2312" %>
<title>Fields List</title>
</head>
<body>
<p><img border="0" src="file:///D:/bea/config/mydomain/applications/DefaultWebApp_myserver/images/redarrow.gif" width="11" height="11"><img border="0" src="file:///D:/bea/config/mydomain/applications/DefaultWebApp_myserver/images/built_bea_web.gif" width="100" height="36"></p>
<p>
<p>
<font size="5" color="#FF00FF"><span style="background-color: #CCCC00">
<marquee scrolldelay="70">WELCOME TO YOU...</marquee>
</p>
<%@ page import="
java.sql.*,java.io.*,java.util.Vector
" %>
<%
//String url = "jdbc:weblogic:mssqlserver4:oydms@ljtcm:1433";
String url = "jdbc:microsoft:sqlserver://mainserver:1433;DatabaseName=test;user=sa;password=sa";
//String url = "jdbc:odbc:MQIS";
//String user = "sa";
//String password = "sa";
Connection conn=null;
Statement stm=null;
ResultSet rs=null;
try {
String sql = "select * from test where name='9999'";
//Class.forName("weblogic.jdbc.mssqlserver4.Driver").newInstance();
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
//Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
//Class.forName("weblogic.jdbc.pool.Driver").newInstance();
conn = DriverManager.getConnection(url);
stm = conn.createStatement();
rs = stm.executeQuery(sql);
while(rs.next())
{
out.println(rs.getString(1)+" "+rs.getString(2)+" "+rs.getString(3));
}
} catch (Exception sqle) {
out.print("Sorry, the database is not available.first catch");
out.print("Exception: " + sqle);
} finally {
if(conn != null)
try {
conn.close();
} catch(Exception sqle) {
out.print("Sorry, the database is not closed.last catch");
out.print("Exception: " + sqle);
}
}
%>
</span></font></p>
<p>
</font>
</body>
</html>