Link to home
Start Free TrialLog in
Avatar of TSK
TSK

asked on

Data from MYsql to JSP page

I know how to INSERT data from a JSP page to the database but how do i get the data from the database and put it into some field on my jsp page? An example would help!
ASKER CERTIFIED SOLUTION
Avatar of cheekycj
cheekycj
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of TSK
TSK

ASKER

How do i make the data coming back from the database a JSP hyperlink to other page?

I want to make the user able to click my Data, which came from the database, and go to another page!
as url parameters?

give me an example url

CJ
Avatar of TSK

ASKER

OK well i have this and i i get back three things from the database. I want to be able to click on the database data to go to the next page....say the next page is www.nextpage.come

<DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<%@ page
    import = "java.io.*"
    import = "java.lang.*"
    import = "java.sql.*"
%>
<TITLE>Diary Central </TITLE>
<META NAME="Generator" CONTENT="TextPad 4.4">
<META NAME="Author" CONTENT="?">
<META NAME="Keywords" CONTENT="?">
<META NAME="Description" CONTENT="?">
</HEAD>

<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#008080" VLINK="#008080"
ALINK="#008080" BACKGROUND="?">
<table width="100%" height="75" border="0" cellpadding="25" align="center"
cellspacing="0" background="?">
<tr>
<td><img src="apple9.jpg" width="100" height="100" align="right">
<td><img src="logo.jpg" width="550" height="100"></td></td>
</tr>
</table>

<table width="90%" height="75" border="0" cellpadding="" align="center"
cellspacing="0" background="?">
<td height="44" colspan="2" bgcolor="#008080"><font face="Times New Roman"
color=#FFFFFF size="5"><b>&nbsp; &nbsp; &nbsp;  custom food.jsp </b></font></td>
</table><BR>

<form action ="edit custom food.jsp" method="get">

<%
  Connection dbconn;
  ResultSet results;
  PreparedStatement sql;
  try
  {
       Class.forName("org.gjt.mm.mysql.Driver").newInstance();
       try
       {
            String name;
            String user, pass1, pass2, email;
            boolean     doneheading = false;
           
            dbconn = DriverManager.getConnection("jdbc:mysql://localhost/nutrition","saundersk","kevin");
     
            sql = dbconn.prepareStatement("SELECT food_name FROM food");
     
            results = sql.executeQuery();
   
            while(results.next())
            {
                 if(! doneheading)
                 {
                      out.println("<table border=2>");
                      doneheading = true;
                     
                 }
             
                 name = results.getString("food_name");
         
                 out.println("<tr><td>" + name);
                 

            }
            if(doneheading)
            {
                 out.println("</table>");
            }
            else
            {
                 out.println("No matches for ");
            }
       }          
       catch (SQLException s)
       {
            out.println("SQL Error");
       }
  }
  catch (ClassNotFoundException err)
  {
       out.println("Class loading error");
     }
%>


<BR>
<table width="90%" height="15" border="0" cellpadding="" align="left"
cellspacing="0" background="?">
<td height="15" colspan="2" bgcolor="#008080"></td>
</table><BR>
<P ALIGN="left">©2003 Diary Central, All Rights Reserved.
</BODY>
</HTML>
Avatar of TSK

ASKER

do i need a date mask or format date to enter dates into my sql?
I don't see the href in the above code.

as far as date goes.. you should require the user to enter it in certain acceptable formats.  If you can parse it.. then create a Date object and use a PreparedStatment to insert it into the DB.

CJ
Thanx for the "A"

CJ