jsolutions
Programmer
I have a simple jsp that opens a connection to an Access database, reads the data, formats it and returns the data to a webpage. In testing it originally, I created a DSN for the database called MyDB and referenced it in the DriverManager.getConnnection method.
My Code is listed below and gives the desired results. My question is, how can I do this on a website. What I mean is that I want to put this database on a website along with the jsp and access the jsp from a web browser to yield the same results. in the getConnection statement, how is the database URL structured : "jdbcdbc:?????".
Also, are there any issues with having the driver on the website? Do I need to upload a specific .jar file?
Finally, if I am missing any other key points about putting a database on a website, other advice is appreciated as well.
Thanks
<code>
<%@ page import="java.sql.*" %>
<html>
<head>
<title>Course Schedule</title>
</head>
<body background="danbg1.gif">
<center>
<h2>Bookmarks</h2>
<p> </p>
<table border=1 cellpadding=5>
<%
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"
Connection con = DriverManager.getConnection( "jdbcdbc:MyDB" );
java.sql.Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery( "select * from tblCategories" );
ResultSetMetaData rsmd = rs.getMetaData();
int numColumns = rsmd.getColumnCount();
out.println( "<tr>" );
for ( int i = 1; i <= numColumns; i++ ) {
out.println( "<td align=\"center\"><b>" + rsmd.getColumnName( i ) + "</b></td>" );
}
out.println( "</tr>" );
out.println();
while ( rs.next() ) {
out.println( "<tr>" );
for ( int i = 1; i <= numColumns; i++ ) {
out.println( "<td>" + rs.getString( i ) + "</td>" );
}
out.println( "</tr>" );
out.println();
}
rs.close();
stmt.close();
con.close();
}
catch (Exception e) {
out.println( "<tr><td>" + e + "</td></tr>" );
}
%>
</table>
</center>
</body>
</html>
</code>
My Code is listed below and gives the desired results. My question is, how can I do this on a website. What I mean is that I want to put this database on a website along with the jsp and access the jsp from a web browser to yield the same results. in the getConnection statement, how is the database URL structured : "jdbcdbc:?????".
Also, are there any issues with having the driver on the website? Do I need to upload a specific .jar file?
Finally, if I am missing any other key points about putting a database on a website, other advice is appreciated as well.
Thanks
<code>
<%@ page import="java.sql.*" %>
<html>
<head>
<title>Course Schedule</title>
</head>
<body background="danbg1.gif">
<center>
<h2>Bookmarks</h2>
<p> </p>
<table border=1 cellpadding=5>
<%
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"
Connection con = DriverManager.getConnection( "jdbcdbc:MyDB" );
java.sql.Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery( "select * from tblCategories" );
ResultSetMetaData rsmd = rs.getMetaData();
int numColumns = rsmd.getColumnCount();
out.println( "<tr>" );
for ( int i = 1; i <= numColumns; i++ ) {
out.println( "<td align=\"center\"><b>" + rsmd.getColumnName( i ) + "</b></td>" );
}
out.println( "</tr>" );
out.println();
while ( rs.next() ) {
out.println( "<tr>" );
for ( int i = 1; i <= numColumns; i++ ) {
out.println( "<td>" + rs.getString( i ) + "</td>" );
}
out.println( "</tr>" );
out.println();
}
rs.close();
stmt.close();
con.close();
}
catch (Exception e) {
out.println( "<tr><td>" + e + "</td></tr>" );
}
%>
</table>
</center>
</body>
</html>
</code>