JSP connects to an Access database (without the method of establishing an ODBC data source) _jsp programming
Source: Internet
Author: User
1. In the site (My site is: E:\javatest) under the establishment of the folder "Accessdb" and under the folder to establish a database "Test.mdb" and the Table "Stu", Stu Field Id,stuname test.mdb the path is: e:\ Under Javatest\accessdb
The following figure:
2. Establish the Test connection database file "accesstest.jsp" under the site (E:\javatest)
The code is as follows:
<%@ page contenttype= "text/html; charset=gb2312 "language=" java "import=" java.sql.* "errorpage=" "%>"
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD" >
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<title>access Connectivity Test </title>
<body>
<%
try{
Class.forName ("Sun.jdbc.odbc.JdbcOdbcDriver");
}
catch (ClassNotFoundException e) {
Out.print (e);
}
try{
Absolute path
String url = "Jdbc:odbc:driver={microsoft Access driver (*.mdb)};D Bq=e:/javatest/accessdb/test.mdb";
Where E:/javatest/accessdb/test.mdb is the absolute path of the database
Relative path
String Strdirpath=getservletcontext (). Getrealpath ("/"); Get the absolute path to the site: E:\javatest\
Out.print (strdirpath+ "<br>");
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.