Hey, first of all... I have no experience on JSP at all so my question might be a bit silly..

However, what I want to do is to query mysql database and get three columns and put them into a table, so that the "URL" column would be a link that I can click to open the file behind that URL.

So I would need to have the link so that when I click it, it would do action that opens the directory path of the URL I click and opens the file from the corresponding column "NAME".

I don't need the actual method to open the file and display(at least not yet), but I would need help to get the link into the table and also some hint how to pass the "URL" and "NAME" variables to the method that opens the file then.

My database structure looks as follows:

mysql> select * from mytab;
+-------+-------------+------+
| name  | url         | id   |
+-------+-------------+------+
| filea | c:/files/a/ |    1 |
| fileb | c:/files/b/ |    2 |
| filec | c:/files/c/ |    3 |
+-------+-------------+------+

and I've written the following so far:

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page import="java.sql.*,java.io.*,javax.servlet.*,javax.servlet.http.*,java.util.*" %>
<%
Connection connection = null;
Statement statement = null;
ResultSet rs = null;
%>

<html><body>
<%
Class.forName("com.mysql.jdbc.Driver").newInstance();

connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/mydb", "root", "root");
statement = connection.createStatement();
rs = statement.executeQuery("SELECT * FROM mytab");

out.println("<table border=2 bordercolor=black>");
out.println("<th>" + "NAME" + "</th>" + "<th>" + "URL" + "</th>" + "<th>" + "ID" + "</th>");
while (rs.next()) {
	out.println("<tr>" + "<td width=150 bgcolor=white>" + rs.getString("NAME") + "<td width=250 bgcolor=white>" + rs.getString("URL") + "<td align=center bgcolor=white>" + rs.getString("ID") + "</tr>");
}
out.println("</table>");
rs.close();
%>

</body></html>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.