<%@ page import="java.sql.*" %>
<!-- '!' tells the computer not to include this in the same method as usual, i.e. _jspService,
when the JSP is translated into a servlet -->
<%!
// Declaration of variables and configuration of database connection
final String dbDriver = "org.gjt.mm.mysql.Driver";
final String dbUser = "";
final String dbPassword = "";
final String dbUrl = "jdbc:
mysql://localhost/indstruksdb"; Connection dbConn = null;
%>
<%!
// One of JSP's default methods. The code in this method is run
// when the JSP is called for the first time only. You often
// use this method to connect to databases and to open files
public void jspInit()
{
// Things that can go wrong are placed in a try / catch structure
// that informs the computer what to do if something goes wrong
try
{ // Get driver for the database
Class.forName( dbDriver ).newInstance();
// Open connection to the database
dbConn = DriverManager.getConnection(dbUrl, dbUser, dbPassword);
} // Catch sentences print out information about the error that has occured
catch (ClassNotFoundException e)
{
System.err.println("Class not found: " + e);
}
catch (InstantiationException e)
{
System.err.println("InstantiationException: " + e);
}
catch (IllegalAccessException e)
{
System.err.println("IllegalAccessException: " + e);
}
catch (SQLException E)
{
System.err.println("SQLException: " + E.getMessage());
System.err.println("SQLState: " + E.getSQLState());
System.err.println("VendorError: " + E.getErrorCode());
}
}
%>
<%!
// One of JSP's default methods. The code in this method is run
// when the JSP is removed from memory. You often use this
// method to close connections to databases and to close files
public void jspDestroy()
{ // Close the connection to database
try { dbConn.close(); }
catch (Exception ignore){}
}
%>
minfil:
<%@ include file="databasejsp.jsp" %>
<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//DA"
"DTD/xhtml1-transitional.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml" xml:lang="da" lang="da">
<head>
<title>
soegfilerJSP
</title>
</head>
<body>
<%
Statement st = dbConn.createStatement();
ResultSet rs = st.executeQuery("SELECT * FROM filer");
%>
<%
while(rs.next())
{
}
%>
</body>
</html>