|
Subject:
|
JAVA Web Database problem
|
|
Posted By:
|
Boonchai
|
Post Date:
|
1/26/2004 3:37:03 AM
|
Can anyone help me find out how to solve this problem ? I created a JAVA Web Database program, but there is a problem with exception report "The server encountered an internal error () that prevented it from fulfilling this request" the root cause is "javax.servlet.ServletException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified"
The strange is that when I try creating a JAVA program running on MS DOS prompt by using the same code for connection. It's working properly.
Can anyone suggest me what I may get mistake ? Thank you so much.
|
|
Reply By:
|
Martyn
|
Reply Date:
|
1/26/2004 4:57:15 AM
|
How are you loading the database driver? It could possibly be a class path problem. Post the segment of code you are using.
Cheers
Martyn
|
|
Reply By:
|
Boonchai
|
Reply Date:
|
1/26/2004 8:22:55 PM
|
Hi Martyn, Here is the code. I have installed j2sdk on my server and set MS-ODBC for j3pmarket database.
<html> <head> <title>j3pMarket Departments </title> </head> <%@ page language="java" import="java.sql.*" %> <body bgcolor=cyan>
<br>
<center><table rows=1 border=1> <tr><td><font size=+6 color=red><b>j3pMarket Departments</b></td></tr> </table></center></font> <% Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection cn = DriverManager.getConnection("jdbc:odbc:j3pmarket", "", "");
Statement stmt = cn.createStatement(); ResultSet rs = stmt.executeQuery("Select * From Employee, Department, City Where " + "(Employee.Dept=Department.idDepartment And Employee.CityOfResidence=City.idCity)" + " Order By Department.idDepartment, idEmployee");
int curDeptID = 0; int deptSecretary = 0; String secretaryMark = ""; if (rs != null) { while (rs.next()) { int deptID = rs.getInt("idDepartment"); if (deptID != curDeptID) { if (curDeptID != 0) { %> </table> </center> <% } String deptName = rs.getString("name"); deptSecretary = rs.getInt("secretary"); String deptPhone = rs.getString("phone"); %> <center> <table border="2" width="600" cols=6 bgcolor=#dddd00> <tr> <td bgcolor="#000099" border="0" colspan=6><p align="center"> <font color=yellow size=+2"> <b> <%= deptName %> Department </td> </tr> <tr> <td bgcolor="#000099" border="0" colspan=6> <font color=white size=+1"> Direct Phone: <%= deptPhone %>, secretary marked with '*' below</b></td> </tr> <tr> <td><b>ID</b></td> <td><b>First Name</b></td> <td><b>Last Name</b></td> <td><b>Employee Date</b></td> <td><b>City</b></td> <td><b>Email Address</b></td> </tr> <% curDeptID = deptID; } int empID = rs.getInt("idEmployee"); if (empID == deptSecretary) secretaryMark = "*"; else secretaryMark = ""; String first = rs.getString("FirstName"); String last = rs.getString("LastName"); String empDate = rs.getString("EmpDate"); String city = rs.getString("cityName"); String email = rs.getString("EmailAddr"); %> <tr> <td><%= empID %><%= secretaryMark %></td> <td><%= first %></td> <td><%= last %></td> <td><%= empDate %></td> <td><%= city %></td> <td><%= email %></td> </tr> <br> <% } } stmt.close(); cn.close(); %> </table> </center> <br> </body> </html>
<Style type="text/css"> A { Color: #0000FF;Text-Decoration: underline } A:Hover { Color: #FF0000;Text-Decoration: underline} </Style>
|
|
Reply By:
|
Martyn
|
Reply Date:
|
1/27/2004 2:05:12 PM
|
Have you set the JAVA_HOME variable. ie JAVA_HOME=C:\jdk1.4
Your classpath should be something like this: CLASSPATH=.;C:\jdk1.4jre\lib\rt.jar;
Is your DSN a System DSN? Check it by using it to import data into Excel.
Let me know how you get on, also I'm assuming thst you are using Access and Tomcat. Is this correct? If not let me know as I have other ideas.
Also, if you wrap a try/catch block around your code you will be able to trap the specific error
Cheers
Martyn
|