File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes How to link JSP to database file (Access 2007) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "How to link JSP to database file (Access 2007)" Watch "How to link JSP to database file (Access 2007)" New topic

How to link JSP to database file (Access 2007)

Jane Ommy

Joined: Apr 16, 2012
Posts: 1
Check my code below. I have tried to compile but is not working. Any help please.

<!DOCTYPE html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<%!//JSP Declaratives begins with '<%!' and ends with '&>'%>
<% //Part A: retrieve form values and perform validation---------
String fName = "";
String lName = "";
String pword = "";

//Retrieve form value when the form is submitted
fName = request.getParameter("firstName");
lName = request.getParameter("lastName");
pword = request.getParameter("password");

//Part B: Display informaton to user
out.println("Dear " +
fName.toUpperCase() + " " + lName.toUpperCase() + "<BR>" +
"Thank you for registration.<BR>");

//End Part B--------------------------------------------------
<table border=1>
<tr><th>First Name</th><th>Surname</th></tr>

out.println("Your details have been recorded. <BR><BR>");

//Part C: Connect to a database (i.e. Microsoft Access)

//type the exact path name: "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=
//followed up by the absolute file address
String accdb = "jdbc:odbc:Driver={Microsoft Access Driver (*.accdb)};DBQ=h:\\203KM\\MyWebsiteProject\\web\\DatabaseDemo.accdb";
Connection conn = DriverManager.getConnection(accdb);

//Part D: Insert form data into the database table, called UserDemo
Statement stm=conn.createStatement();

String sql = "INSERT INTO UserDemo VALUES ('" + fName + "','" + lName + "','" + pword + "')";

//Part E: Retrieve data that matches teh crieteri from teh database table
ResultSet rs=st.executeQuery("select * from UserDemo " +
"WHERE FName = '" + fName + "' and LName ='" + lName + "'");
while ({ %>


catch(Exception e){}

Change your password? Click <a href="UpdateForm.html">here</a>.

I agree. Here's the link:
subject: How to link JSP to database file (Access 2007)
jQuery in Action, 3rd edition