JSP Operations Access database

Source: Internet
Author: User
Tags odbc stmt access database tomcat server

SP Operations Access database
Recently in the use of JSP to write the company's Web site sample program, used in the JSP operation Access database, a lot of things are not difficult, but we do not know. ^-^ hehe, so now I wrote a small program, to the use of JSP operation Access database program demo as follows, I hope that we can save the pain of searching things.
First , I wrote a databasedemo.jsp page, the specific code is as follows, this is the specific process of operating the database.
databasedemo.jsp The page code is as follows:
<%@ page language= "java" contenttype= "text/html;charset=gb2312"%>
<%@ page import= "java.sql.*"%>
<%@ page import= "java.io.*"%>

<%

String usernamev= "";
String passwordv= "";

Try
{

$False $

Path
   String p=request.getservletpath ();
      string path= Request.getrealpath (P);
   path=path.substring (0,path.lastindexof (""));
      string dbpath=path+ "Userdatabase.mdb";       < Span class= "Apple-converted-space" > 
 
   String dbname= "";
   String user= "";
   
  //Connecting to the connection string for an Access database
    String url= "Jdbc:odbc:driver={microsoft Access Driver (*.mdb)};D bq=" +dbpath;
 
  // Create connection objects and statement objects.
       class.forname ("Sun.jdbc.odbc.JdbcOdbcDriver");
       connection conn=drivermanager.getconnection (URL);
       statement stmt=conn.createstatement (resultset.type_scroll_sensitive, resultset.concur_updatable);
&NBSp
 string sql= "select * from UserInformation";
 resultset rs=stmt.executequery (SQL);
 
 while (Rs.next ())
 {
     usernamev=rs.getstring ("UserName");
     passwordv=rs.getstring ("PassWord

Br>
Out.print ("User name:" +rs.getstring ("UserName"));
Out.print ("User name:" +usernamev+ "<br>");
Out.print ("Password:" +PASSWORDV);
}
Rs.close ();
Stmt.close ();
Conn.close ();

}
catch (Exception e)
{//error
Out.print ("An error has occurred!") ");
}
%>
second , I set up a virtual directory for this page under the Tomcat server, while the test database Userdatabase.mdb and pages are placed under the same directory. Then enter the http://localhost:8080/myapp/sub/DatabaseDemo.jsp in IE to see the result.

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.