Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to link JSP to database file (Access 2007)  RSS feed

Jane Ommy
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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>.

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!