龙刺绣西服:有关Jsp连接Access以及JDBC,SQL的问题

来源:百度文库 编辑:高考问答 时间:2024/04/19 20:34:11
Jsp怎么连接Access数据库?还要装JDBC吗?要怎么安装JDBC啊?安装完了之后怎么连接?如何显示,查询,修改数据表中的内容?Access支持SQL语言吧?请如数回答.谢谢!!
1楼的大侠,能否解释一下你的代码中分别都是哪里显示,查询,修改数据表中的内容的?

jsp连接access数据库不需要装jdbc
给你个servlet的例子吧,可以直接运行的.

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.sql.*;

public class ConnectAccess extends HttpServlet {
Connection conn = null;
Statement stmt = null;

public void init() throws ServletException {
String strurl="jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=D:\\books.mdb";
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn=DriverManager.getConnection(strurl);
stmt=conn.createStatement();
} catch (Exception e) {
System.out.println(e.getMessage());
}
}

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;");
PrintWriter out = response.getWriter();
try {
ResultSet rs=stmt.executeQuery("select * from books");
out.println("<html><body>");
out.println("<p>Database connection successfully created!</p>");

while (rs.next()) {
out.println("<p>The book's name is: " + rs.getString("book") +"</p>");
}
out.println("</body></html>");
} catch (Exception e) {
System.out.println(e.getMessage());
}
}

public void destroy() {
try {
conn.close();
} catch(SQLException e){}
}
}

jsp 连接数据库 只要配置好数据源 然后使用 代码连接就可以了啊!