Hi,

Like the title says I am having a little difficulty connecting a JSP page to database.Here is my code containing the setDataSource, I am pretty sure that this is whats causing the problem.

<%@ taglib prefix="sql" uri="htpp:/java.sn.com/jsp/jstl/sql" %>

<sql:setDataSource
		var = "labdb"
		scope = "session"
		driver = "sun.jdbc.odbc.JdbcOdbcDriver"
		url = "jdbc:odbc:labdb"
/>

<sql:query var="userList" scope="request" dataSource = "${labdb}">
	SELECT	*	FROM User
	WHERE		FirstName	 Like	?
		AND		LastName  Like	?
		AND		Department LIKE ?
	ORDER		BY LastName
	<sql:param value="%${param.firstName}%" />
	<sql:param value="%${param.lastName}%" />
	<sql:param value="%${param.password}%" />
</sql:query>
<jsp:forward page="list.jsp" />

My database is called labdb, and I am using windows 7.I a trying to make my connection by :

- going to control panel ->Data Sources(ODBC)
- Adding a new db, called labdb

This is where I am running into some confusion.Should I just type in the DSN name, or use the filepath where I have stored my database.

I have tried both ways and nothing seems to work, I would appreciate any help however little very much.
Thank you.

so much fundamentally wrong here, it doesn't warrant even starting to list the problems.
Begin with a good RECENT book on JSP, the JDBC tutorial, and a decent database (no, Access isn't one).

Well could you tell me what the problem is with the sql setdatasource tag.
And i need to use access as it it part of my assignment!

<%@ page language="java" import="java.sql.*" errorPage="" %>
<%
        Connection conn = null;
        
        Class.forName("com.mysql.jdbc.Driver").newInstance();
        String jdbcURL="jdbc:mysql://localhost:3306/databaseName";
        conn = DriverManager.getConnection(jdbcURL,"username", "password");
        
        PreparedStatement psSelectRecord=null;
        ResultSet rsSelectRecord=null;
        String sqlSelectRecord=null;
   
        sqlSelectRecord ="SELECT * FROM staff_register";
        psSelectRecord=conn.prepareStatement(sqlSelectRecord);
        rsSelectRecord=psSelectRecord.executeQuery();
 
%>
<html>
<head>
<title>View records in JSP through database</title>
<style>
td
{
text-align:center
}
</style>
</head>

<body>
<h1>View Record from Database through JSP</h1>

S. No |  EmpID | Staff Name | Staff Department | Staff Phone <br>
 
  <%
  int cnt=1;
  while(rsSelectRecord.next())
  {
  %>
   <%=cnt%>
   <%=rsSelectRecord.getString("iEmpID")%> 
   <%=rsSelectRecord.getString("sStaffName")%> 
   <%=rsSelectRecord.getString("sStaffDept")%> 
   <%=rsSelectRecord.getString("iStaffPhone")%>
   
  <br>
  <%
   cnt++;   /// increment of counter
  } /// End of while loop
  %>

</body>
</html>
<%
try{
          if(psSelectRecord!=null)
          {
            psSelectRecord.close();
          }
          if(rsSelectRecord!=null)
          {
            rsSelectRecord.close();
          }
          
          
          if(conn!=null)
          {
           conn.close();
          }
        }
        catch(Exception e)
        {
          e.printStackTrace(); 
        }
%>
commented: BAD, database conenction bellongs to server side not client -2

@anuplike classic example of what you should not do in page view but on server side.

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.