• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to link JSP to database file (Access 2007)

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check my code below. I have tried to compile but is not working. Any help please.

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%!//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)
try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");


//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 + "')";
st.executeUpdate(sql);

//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 (rs.next()){ %>
<tr><td><%=rs.getString("FName")%>
</td><td><%=rs.getString("SName")%>
</td></tr><%}rs.close();

st.close();
con.close();}

catch(Exception e){}
%>

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

</body>
</html>
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic