Link to home
Start Free TrialLog in
Avatar of DoughBoy
DoughBoy

asked on

Getting data from an MS Access Database

Hi All,
Below is my psuedo code JSP page. What do I need to adjust in order to connect to an MS Access MDB file with or without a DSN reference, open the database, search and retrieve a string from the datbase.

TIA,
DoughBoy


//what other packages should I import
<%@ page import="java.sql.*" %>

<%
String sDefinition = "";
String sLabelString = "";

sLabelString = request.getParameter("currlabel"));

//what driver do I need????????????
Class.forName("some.class.odbc.ms.access.Driver");
         
// what Parameters do I need????????????? for an
// MS Access database with or with a DSN reference.
Connection conn = DriverManager.getConnection("odbc:dsn://mymdbfile", "someuser-not-needed", "somepwd-not-needed");
             
PreparedStatement stmt1 = conn.prepareStatement("select resultstring from mytable where column1data =" + string1 + " and column2data = " + sLabelString);

ResultSet rs = stmt1.executeQuery();

while (rs.next())
{
sDefinition = rs.getString(1);
}
rs.close();
conn.close();
%>

<html>
<head>
<title>ODBC Result String</title>
</head>
<body>

<p> <% =sDefinition %> </p>

</body>
</html>
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

I think you need to use DSN to connect to M$ Access database..
ASKER CERTIFIED SOLUTION
Avatar of kotan
kotan
Flag of Malaysia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of DoughBoy
DoughBoy

ASKER

thanks very much