Re: [JSP] Connecting to a MySQL database
From: Sarb Singh (sarbs_exeige_at_hotmail.com)
Date: 11/12/03
- Previous message: Alex Molochnikov: "Re: Small Footprint Database"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 12 Nov 2003 07:20:21 GMT
<%@page language="java" import="java.sql.*, java.util.Date"%>
<html>
<body>
<center>
<b>News</b>
</center>
<br>
<%Connection conxn;
String selectnews;
ResultSet rs;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conxn = DriverManager.getConnection("jdbc:odbc:userdsn", "sarb", "khalsa");
Statement stmt01 = conxn.createStatement();
// selectnews = "select * from news where approved = true";
selectnews = "select * from news where approved = true and expiry>=Now()";
rs = stmt01.executeQuery(selectnews);
out.println("<table border=1>");
out.println("<tr bgcolor='yellow'><th>Posted
by</th><th>Category</th><th>Headlines</th><th>News in Detail</th><th>Date
Posted</th><th>Date of Expiry</th></tr>");
while (rs.next())
{
out.println("<tr bgcolor='pink'><td>" + rs.getString("username") +
"</td><td>" + rs.getString("cat_id") + "</td><td>" +
rs.getString("headline") + "</td><td>" + rs.getString("details") +
"</td><td>" + rs.getDate("posted") + "</td><td>" + rs.getDate("expiry") +
"</td></tr>");
}
out.println("</table>");
}
catch(Exception e)
{
out.println(e);
}
%>
</body>
</html>
"Yann Laviolette" <yann_laviolette@gnome.org> wrote in message
news:pan.2003.10.13.16.48.44.739645@gnome.org...
> Hi!
>
> I'm unable to connect to my db. When I use NetBeans to connect to the
> database all works. But I don't know how to do a connection in Java
> [JSP]...
>
> Can somebody told me how, in details?
>
> Thanks in advance!
>
> Yann Laviolette
>
- Previous message: Alex Molochnikov: "Re: Small Footprint Database"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]