You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Law Kim Soon <ki...@tm.net.my> on 2001/12/28 09:48:35 UTC
Java file bug
Hi all,
I can't solve the problem in Lesson14.java.Hope to get some help here.
Error message
---------------------
cannot resolve symbol
-basically,the errors are about the classes(DriverManager,ResultSet,PreparedStatement,Connection...)
I hope u guys can help me solve these bugs
Lesson14.java
---------------------
package rayexamples;
import java.sql.*;
import java.io.Serializable;
public class Lesson14 extends Object implements Serializable
{
public Lesson14() {}
private String deptId ;
private String deptName ;
private String deptEmpId ;
/* THE SETTER METHOD FOR deptId - This is the key column, & it identifies the dept.*/
public void setDeptId(String deptId) { this.deptId = deptId ; }
/* THE SETTER METHOD FOR deptName. This is the name of the dept (accounting, etc.) */
public void setDeptName(String deptName) { this.deptName = deptName; }
/* THE SETTER METHOD FOR deptEmpId. This the employee ID of the department's manager.*/
public void setDeptEmpId(String deptEmpId) { this.deptEmpId = deptEmpId ; }
/* = = = = = = = = = > INSERT DEPTARTMENT < = = = = = = = = = */
public String insertDept ()
{
Connection sqlca = null;
String lesson14_output = "";
PreparedStatement lesson14_stmt= null;
ResultSet lesson14_data= null;
int myDeptId = 0;
int myDeptEmpId = 0;
/* = = = = = = = = = > CONNECT < = = = = = = = = = */
try
{
/* Connection to the database */
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String lesson14_database = "jdbc:odbc:lesson14_database";
String usr="E-BookMall Admin";
String pwd="peilengdh00677833811";
sqlca = DriverManager.getConnection(lesson14_database,usr,pwd);
}
catch (Exception e)
{
lesson14_output = "<br>Connection Error #1: JDBC Class creation: " + e.getMessage()+"<br><br>";
}
/* = = = = = = = = = > INSERT < = = = = = = = = = */
/* Convert deptId from a string to an integer. */
try
{
myDeptId = Integer.parseInt(deptId.trim());
}
catch (NumberFormatException e)
{ lesson14_output = " <br>Convert Error #1 Number Format Exception: " + e.getMessage(); }
catch (NullPointerException e)
{ lesson14_output = " <br>Convert Error #2: NullPointerException: " + e.getMessage(); }
/* Convert deptEmpId from a string to an integer. */
try
{
myDeptEmpId = Integer.parseInt(deptEmpId.trim());
}
catch (NumberFormatException e)
{ lesson14_output = " <br>Convert Error #3 Number Format Exception: " + e.getMessage(); }
catch (NullPointerException e)
{ lesson14_output = " <br>Convert Error #4: NullPointerException: " + e.getMessage(); }
/* Create and execute the insert statement. */
try
{ lesson14_stmt = sqlca.createStatement() ;
}
catch (Exception e)
{ lesson14_output = " <br>Insert Error #1: SQL error of: " + e.getMessage();
}
try
{ int rowsAffected = lesson14_stmt.executeUpdate(
"insert into department " +
"(dept_id, dept_name, dept_head_id) " +
"values (" + myDeptId + ", '" + deptName + "', " + myDeptEmpId + " )");
if ( rowsAffected == 1 )
{ lesson14_output = "Department WAS added.<br><br>";}
else
{ lesson14_output = "Department WAS NOT added.<br><br>";}
}
catch (Exception e)
{ lesson14_output += "<br>Department was not added." +
"<br><br>Insert Error #2: SQL error of: " + e.getMessage(); }
/* = = = = = = = = = > DISPLAY DEPARTMENT < = = = = = = = = = */
try
{
/* Build & execute the sql, positioning before the first row in the result set */
lesson14_stmt = sqlca.createStatement();
lesson14_data = lesson14_stmt.executeQuery(
"select " +
"dept_id, " +
"dept_head_id, " +
"dept_name " +
"from department " +
"where dept_id = " + myDeptId );
/* Construct the heading for the table */
lesson14_output +=
"<br><br><table border=1 align=center width=75%>" +
"<caption><i><b>The Current State Of Department " +
this.deptId + "</b></i></caption>" ;
/* "<caption><i><b>The Current State Of Department </b></i></caption>" ; */
/* Construct the column headings for the table */
lesson14_output +=
"<i><b><th align=left>Dept ID</th>" +
"<th>Dept Name</th>" +
"<th>Dept Manager</th></b></i>" ;
/* Move to the first (and only) row and & add its contents to the html output */
lesson14_data.next() ;
{ lesson14_output += "<TR><TD>" +
lesson14_data.getObject("dept_id").toString() + "</TD><TD>" +
lesson14_data.getObject("dept_name").toString()+"</TD><TD>" +
lesson14_data.getObject("dept_head_id").toString() + "</TD></TR>" ;
}
lesson14_stmt.close();
}
catch (Exception e)
{
lesson14_output += " <br>Display Error #1: SQL error of: " + e.getMessage() ;
}
catch (Exception e)
{
lesson14_output += " <br>Display Error #2: JDBC Class creation: " + e.getMessage();
}
lesson14_output += "</table><br><br>" ;
/* = = = = = = = = = DISCONNECT = = = = = = = = = */
try
{ sqlca.close(); }
catch (Exception e)
{ lesson14_output = "<br>Disconnect Error #1: SQL error of: " + e.getMessage(); }
/* Complete the html and return it to the Java Server Page */
return lesson14_output;
}
}