2012-01-20 53 views
0

我無法毫秒的存取連接我的jsp頁面 它說無法使用的MS Access連接我的jsp頁面

"java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified" 

我創建了一個DSN,但仍然問題是一樣..

我搜查了淨廣泛,但不能糾正....

DriverManager.getConnection("jdbc:odbc:students"); 

此行是造成異常.... 我選擇了DNS仍數據源太....我米使用Access ....

這裏的一切:

<%@page import="java.sql.PreparedStatement"%> 
<%@page import="java.sql.DriverManager"%> 
<%@page import="java.sql.Connection"%> 
<%@page contentType="text/html" pageEncoding="UTF-8" language="java"%> 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd"> 

<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
<title>JSP Page</title> 
</head> 
<body> 

<% 

PreparedStatement pstm; 
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); 

//connection object created using DriverManager class 
//employee is the name of the database 
Connection connect =DriverManager.getConnection("jdbc:odbc:employee"); 

//creating prepared statement object pstm so that query can be sent to database 
pstm=connect.prepareStatement("insert into employee values(?,?,?,?)"); 
pstm.setString(1,"5"); 
pstm.setString(2,"parth"); 
pstm.setString(3,"parth"); 
pstm.setString(4,"10000"); 
//execute method to execute the query 
pstm.executeUpdate(); 
out.println("Record Added Successfully"); 
pstm.close(); 

connect.close(); 
%> 
</body> 
</html> 

回答

-1

你可以通過創建一個新的空文件(幾乎任何地方,桌面將正常工作),與你喜歡的任何名稱測試你的數據源配置和將擴展名更改爲.udl

當您更改擴展名時,圖標會更改。然後雙擊它,您應該在第一個組合(Use data source name)中看到students數據源,選擇它並單擊Test Connection

如果一切順利了這一點,然後你的數據源是確定的,問題是你的代碼,這應該是這樣的http://www.kodejava.org/examples/151.html