标题:JDBC-ODBC桥连接SQLSERVER的问题
只看楼主
weimingyu
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2005-11-25
 问题点数:0 回复次数:1 
JDBC-ODBC桥连接SQLSERVER的问题

大家好,问题一个,能否请指教:是JSP的 JDBC-ODBC桥连接SQLSERVER的

TOMCAT,SQL SERVER2000 FOR JDBC,SQL SERVER2000 SP3都已安装,ODBC设好了,CLASSPATH环境变

量也设好了
代码是:
<%@ page import="java.sql.*"%>
<%@ page import="java.text.*"%>
<%@ page import="java.util.*"%>
<html>
<head><title>sdf</title></head>
<body>
sdfasdfadfsdfasdfadfsdfasdfadfsdfasdfadf
<%

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
Connection con=DriverManager.getConnection("jdbc:odbc:ggy","gg","gg");
Statement sql=con.createStatement();
ResultSet rs=sql.executeQuery("SELECT * FROM student");

%>

<%=rs.getString("sd")%>
<%
con.close();
%>

</body>
</html>

但还是出错,提示是:
javax.servlet.ServletException: [Microsoft][ODBC 驱动程序管理器] 未发现数据源名称并且未指

定默认驱动程序
org.apache.jasper.runtime.PageContextImpl.doHandlePageException

(PageContextImpl.java:825)
org.apache.jasper.runtime.PageContextImpl.handlePageException

(PageContextImpl.java:758)
org.apache.jsp.text_jsp._jspService(text_jsp.java:160)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

同样的设置我用驱动连接又成功,驱动代码是:
<%@ page contentType="text/html; charset=GBK" language="java"

import="java.sql.*,java.io.*"%>
<html>
<body>
以下是从Ms sql server数据库读取的数据:<hr>
<table border=1>
<tr><td>id</td><td>书名</td><td>出版社</td><td>价格</td></tr>
<%! String trans(String chi)
{
String result = null;
byte temp [];
try
{
temp=chi.getBytes("iso-8859-1");
result = new String(temp);
}
catch(UnsupportedEncodingException e)
{
System.out.println (e.toString());
}
return result;
}
%>
<%

Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
Connection con=java.sql.DriverManager.getConnection

("jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=MJ","gg","gg");
Statement stmt=con.createStatement();
ResultSet rst=stmt.executeQuery("select * from student;");
while(rst.next())
{
out.println("<tr>");
out.println("<td>"+trans(rst.getString("sd"))+"</td>");
out.println("<td>"+trans(rst.getString("sdf"))+"</td>");
out.println("<td>"+trans(rst.getString("ae"))+"</td>");

out.println("</tr>");
}

rst.close();
stmt.close();
con.close();
%>
</table>
</body>
</html>

搜索更多相关主题的帖子: html import title 
2005-11-25 21:12
jeremydomett
Rank: 2
等 级:新手上路
威 望:3
帖 子:312
专家分:0
注 册:2004-6-10
得分:0 

如果jdbc驱动可以连接成功.
那么上面的就是odbc 没有设置好.


热爱编程........永不放弃.........
2005-11-26 13:42



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-35163-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.036041 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved