开发者

Connect MS access database in JSP pages

开发者 https://www.devze.com 2023-04-12 04:01 出处:网络
I would like to ask you how can I connect a MS access database in JSP pages?Do you kn开发者_如何转开发ow any ready class which I can use?I am using Netbeans to create JSP pages!Ancient question, but I

I would like to ask you how can I connect a MS access database in JSP pages?Do you kn开发者_如何转开发ow any ready class which I can use?I am using Netbeans to create JSP pages!


Ancient question, but I shall answer anyway. Had to Google around a bit when the same question flummoxed me. Here goes (concise version of stuff found here):

Administratively Register Database

  1. Use MS Access to create a blank database in some directory. (eg. Database1.mdb.) Make sure to close the data base after it is created.

  2. Go to: Control panel -> Admin tool -> ODBC

  3. Under the System DSN tab (for Tomcat version 5 or later – User DSN for earlier versions), un-highlight any previously selected name and then click on the Add button.

  4. On the window that then opens up, highlight MS Access Driver & click Finish.

  5. On the ODBC Setup window that then opens, fill in the data source name. This is the name that you will use to refer to the data base in your Java program – like
    arc. This name does not have to match the file name.
    .

  6. Then click Select and navigate to the already created database in directory.
    Suppose the file name is Database1.mdb. After highlighting the named file,
    click OKs all the way back to the original window.

Connect a JSP page to an Access Database

 <%@ page import="java.sql.*" %>

    <%
            Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");             
            Connection  conn=null;  
    conn = DriverManager.getConnection("jdbc:odbc:arc", "", "");  
    out.println ("Database Connected.");
    %>


Now that the JDBC-ODBC Bridge has been removed from Java 8, the UCanAccess JDBC driver may be a more relevant option for future users. For details, see the related Stack Overflow question

Manipulating an Access database from Java without ODBC

0

精彩评论

暂无评论...
验证码 换一张
取 消