jsp+servlet怎么存取access数据库
有个项目要把sql2000的数据存到access里.jsp+servlet怎么存取access数据库?要用到哪些包?有例子就更好了,多谢了!
------解决方案--------------------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){}
}
}
------解决方案--------------------除了连接串变一下,其余的和SQLSERVER一样。
jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=D:\\books.mdb ";
------解决方案--------------------注册两个连接,把从sql2000读取的数据插入到access中不就行了?