关于Weblogic6.1和SQLServer7.0的数据库连接的问题。

yshao 2002-09-26 10:42:46
代码如下:
infomation为数据源:
IP地址为:118.1.1.111

<%@ page import="java.sql.*" contentType="text/html;charset=gb2312"%>

<%
String url=new String();
url="jdbc:weblogic:infomation";
Class.forName("weblogic.jdbc.pool.Driver");
try
{
Connection con=DriverManager.getConnection(url,"sa","");
Statement stat=con.createStatement();
String sql=new String();
sql="select * from tab";
ResultSet rs=stat.executeQuery(sql);
while (rs.next())
{
String name=new String();
name=rs.getString("Username");
out.println(name);
}
rs.close();
stat.close();
con.close();
}
catch(SQLException e)
{
out.println(e);
}
%>

出错的信息为:java.sql.SQLException: No suitable driver
请问各位高手,哪里出错了呀,怎么修改?

...全文
31 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
yshao 2002-09-27
  • 打赏
  • 举报
回复
请问我想用连接池的方法实现怎么做呀?
谢谢各位高手了。
yshao 2002-09-26
  • 打赏
  • 举报
回复
难道就没有一个人知道吗?
帮帮忙呀,各位高手!
maxpain 2002-09-26
  • 打赏
  • 举报
回复
===============这个是使用weblogic的连接数据源来连接
Hashtable ht = new Hashtable();

ht.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");

ht.put(Context.PROVIDER_URL,"t3://localhost:7001");



try

{

Context ctx = new InitialContext(ht);

DataSource ds = (DataSource)ctx.lookup("SQLServer");

Connection con = ds.getConnection("system","12345678");//此处是WebLogic的域用户和密码

Statement st = con.createStatement();

ResultSet res = st.executeQuery("select * from employees");

String line = "";

while (res.next())

line = line + res.getString("notes")+"\n";

jTextArea1.setText(line);

con.close();

}

catch (Exception ex)

{

jTextArea1.setText("error : "+ex.getMessage());

}
==========使用类装载直接连接
try

{

Class.forName("weblogic.jdbc.mssqlserver4.Driver");

Connection con = DriverManager.getConnection("jdbc:weblogic:mssqlserver4:northwind@localhost","sa","");//此处根据你的SQLServer帐户而定。

Statement st = con.createStatement();

ResultSet res = st.executeQuery("select * from employees");

String line = "";

while (res.next())

line = line + res.getString("title")+"\n";

jTextArea1.setText(line);

con.close();

}

catch (Exception ex)

{

jTextArea1.setText("error : "+ex.getMessage());

}
钟伟海 2002-09-26
  • 打赏
  • 举报
回复
guanzhu
dsdai 2002-09-26
  • 打赏
  • 举报
回复
你可以试一试 URL jdbc:odbc:数据源
classname sun.jdbc.odbc.JdbcOdbcDriver

1,236

社区成员

发帖
与我相关
我的任务
社区描述
企业软件 中间件技术
社区管理员
  • 中间件
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧