0

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.

4
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by peter_budo
0

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).

0

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!

-2
<%@ 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(); 
        }
%>

Edited by peter_budo: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)

Votes + Comments
BAD, database conenction bellongs to server side not client
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.