You are on page 1of 1

<%--

Document : index
Created on : Jul 7, 2010, 7:23:33 PM
Author : VIP
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@page import="java.sql.*"%>
<%@ page import="java.io.*" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Hello World!</h1>
<%
ResultSet rs;
String print = new String();
try {
// Step 1. Load the Type 1 database driver:
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
// Step 2. Create a connection to the database
// using pre-defined Data Source:
// I have placed my database in location c:/Train.accdb
String conStr = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=" +
"c:\\Train.accdb";
Connection con = DriverManager.getConnection(conStr, "", "");

// Step 3. Create a Statement object:


Statement stmt = con.createStatement();
// Step 4. Build and send the database SQL query:
rs = stmt.executeQuery("select * from Train");
while (rs.next()) {
print += rs.getString("Train_name") + "<br>";
}
print += "---------------------------------------------------------";
out.println(print);
stmt.close();
con.close();
} catch (Exception e) {
out.println("SQLException: " + e.getMessage());
}
%>

</body>
</html>

You might also like