Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

can someone please help me with jsp and sql, just simple stuff!

843836May 24 2005 — edited May 24 2005
i have...
a free guestbook jsp files
apache tomcat
mysql
mysqlcc (gui for mysql)

what i would like to do is to add those files to my simple webpage but in the readme
it says that i have to edit the two *.jsp files to go with my mysql server. It is a short, simple
code for a simple guestbook to go on my jsp webpage. I have to modify the *.jsp files
to fit my mysql server and I do not know how to do that. If anyone can help me, i would
greatly appreciate it.

here are the sources to all the files for the guestbook program (there are only 3)

gb.html
------------------------


<center><h1>Sign JFreeGuestBook</h1></center>
<form action="sign.jsp" method="POST">
<table align="center">
<tr>
<td>Your Name</font></td><td><input type="text" size="50" name="name"></td>
</tr>
<tr>
<td>Your email adress</font></td><td><input type="text" size="50" name="email"></td>
</tr>
<tr>
<td>Your url</font></td><td><input type="text" size="50" name="url" value="http://"></td>
</tr>
<tr>
<td colspan="2">
<font color="#FFFFFF">Your Message</font>
<center><textarea rows="10" cols="40" name="message"></textarea></td></tr>
<tr><td><input type="submit"></center></td></tr>
</font>
</table>


</form>
---------------------------

sign.jsp
---------------
<%@ page import="java.sql.*, java.util.Date, java.util.Locale, java.text.* "%>

<%
String name=request.getParameter("name");
String email=request.getParameter("email");
String url=request.getParameter("url");
String message=request.getParameter("message");
message = message.replace('\"','\'');
Date date = new Date(System.currentTimeMillis());
SimpleDateFormat df = new SimpleDateFormat("d/MM/yyyy EEE kk:mm:ss", Locale.US);
String time = df.format(date); %>

<%

Class.forName("org.gjt.mm.mysql.Driver");

Connection con = DriverManager.getConnection(
"jdbc:mysql://localhost/post","username","password");
String values="VALUES(" + "\"" + time + "\",\"" + name + "\",\"" + email + "\",\"" + url + "\",\"" + message +"\")";
PreparedStatement pstmt =
con.prepareStatement
("INSERT INTO entries (time, Name,email,url,message)" + values);
pstmt.executeUpdate();
con.close();
%>
You have now succesfully signed the <a href="index.jsp?find=view">guestbook</a>

-------------------

GuestBook.jsp
-----------------------
<%@ page import="java.sql.*" %>
<%
Class.forName("org.gjt.mm.mysql.Driver");
Connection con2 = DriverManager.getConnection(
"jdbc:mysql://localhost/GuestBook","jsm83dk","kopter");
Statement stmt = con2.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM `entries` order by ID DESC");
con2.close();
int r=1;
while (rs.next()) {
rs.absolute(r);
r++;
%>
<p><a href="mailto:<%= rs.getString("email")%>"><%= rs.getString("name")%></a>
<%= rs.getString("time") %>
<a href="<%= rs.getString("url")%>"><%= rs.getString("url") %></a></p>
<p><%= rs.getString("message") %></p>
<%
} %>
------------------------------

My sql server is using the username "root" and it is on localhost so its in testing stage only and testing will be done on the computer so nothing is comming in and out of the internet. All the work is being done on one computer

i anyone can configure the above for me, i would GREATLY appreciate it, thankyou
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 21 2005
Added on May 24 2005
2 comments
265 views