Topic: JSP 调用 Access (Tomcat)问题?

  Print this page

1.JSP 调用 Access (Tomcat)问题? Copy to clipboard
Posted by: js_yy
Posted on: 2004-11-18 13:09

JSP 调用 Access (Tomcat)问题?

说明:应用服务器: Apache Tomcat/4.1.31
用JSP 调用 Java Bean
由Java Bean完成数据库相关操作
我的javabean 相关代码

数据库连接的代码如下:

// ============== Make connection to database ==================

//load the driver class
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

//Specify the ODBC data source
String sourceURL = "jdbc:odbc:TicketRequest";

//get a connection to the database
dbConn = DriverManager.getConnection(sourceURL);

数据源我以前作别的程序测试过,没有问题

jsp 执行时候的数据连接不成功:
查看日志文件:
错误如下:Exception was thrown: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

没有找到数据源的名字,没有指定的默认驱动?
Why?

是不是还要在添加一些.jar文件?

2.Re:JSP 调用 Access (Tomcat)问题? [Re: js_yy] Copy to clipboard
Posted by: songaihua
Posted on: 2005-01-18 19:08

写法错误
<%@ page contentType="text/html; charset=gb2312" %>
<%@ page import="java.sql.*"%>
<%@ page import="java.util.*"%>
<%@ page import="sun.jdbc.odbc.*"%>

<%

Connection con=null;
String DriverName="sun.jdbc.odbc.JdbcOdbcDriver";
////////采用指定路径的方法.不用建立数据源.
// String URL="jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=c:/data/test.mdb";
////////采用建立数据源的方法.在系统数据源中建立test的数据源.用户是test,密码是test.
String URL="jdbc:odbc:test";
String user="test";
String password="test";
try{
Class.forName(DriverName);
con = DriverManager.getConnection(URL,user,password);
}catch(Exception ne)
{
out.println(ne);
}

Statement stmt=con.createStatement();
ResultSet rst=stmt.executeQuery("select * from teacher ");
out.println("--------------------");
out.println("<br>");
while(rst.next())
{
out.println("ID号:"+rst.getString("teacherid")+"---"+"姓名:"+rst.getString("teachername"));
out.println("<br>");  
}
rst.close();
stmt.close();
con.close();
%>


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923