• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 425
  • Last Modified:

-Xlint:unchecked warning, File will not compile.

I am trying to compile the code I have included below.  It gives me a warning Note: C:\Tomcat 6.0\webapps\burnaby\WEB-INF\classes\com\brainysoftware\burnaby\DbBean.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

It doesnt compile and iIam not sure how to get past this error.
package com.brainysoftware.burnaby;
 
import java.util.Hashtable;
import java.util.ArrayList;
import java.util.Enumeration;
import java.sql.*;
 
 
public class DbBean {
  public String dbUrl = "";
  public String dbUserName = "";
  public String dbPassword = "";
 
  public void setDbUrl(String url) {
    dbUrl = url;
  }
  public void setDbUserName(String userName) {
    dbUserName = userName;
  }
  public void setDbPassword(String password) {
    dbPassword = password;
  }
 
  public Hashtable getCategories() {
    Hashtable categories = new Hashtable();
    try {
      Connection connection = DriverManager.getConnection(dbUrl, dbUserName, dbPassword);
      Statement s = connection.createStatement();
      String sql = "SELECT CategoryId, Category FROM Categories" +
        " ";
      ResultSet rs = s.executeQuery(sql);
      while (rs.next()) {
        categories.put(rs.getString(1), rs.getString(2) );
      }
      rs.close();
      s.close();
      connection.close();
    }
    catch (SQLException e) {}
    return categories;
  }
 
  public ArrayList getSearchResults(String keyword) {
    ArrayList products = new ArrayList();
    try {
      Connection connection = DriverManager.getConnection(dbUrl, dbUserName, dbPassword);
      Statement s = connection.createStatement();
      String sql = "SELECT ProductId, Name, Description, Price FROM Products" +
        " WHERE Name LIKE '%" + keyword.trim() + "%'" +
        " OR Description LIKE '%" + keyword.trim() + "%'";
      ResultSet rs = s.executeQuery(sql);
      while (rs.next()) {
        Product product = new Product();
        product.id = rs.getInt(1);
        product.name = rs.getString(2);
        product.description = rs.getString(3);
        product.price = rs.getDouble(4);
        products.add(product);
      }
      rs.close();
      s.close();
      connection.close();
    }
    catch (SQLException e) {}
    return products;
  }
 
  public ArrayList getProductsInCategory(String categoryId) {
    ArrayList products = new ArrayList();
    try {
      Connection connection = DriverManager.getConnection(dbUrl, dbUserName, dbPassword);
      Statement s = connection.createStatement();
      String sql = "SELECT ProductId, Name, Description, Price FROM Products" +
        " WHERE CategoryId=" + categoryId;
      ResultSet rs = s.executeQuery(sql);
      while (rs.next()) {
        Product product = new Product();
        product.id = rs.getInt(1);
        product.name = rs.getString(2);
        product.description = rs.getString(3);
        product.price = rs.getDouble(4);
        products.add(product);
      }
      rs.close();
      s.close();
      connection.close();
    }
    catch (SQLException e) {}
    return products;
  }
 
  public Product getProductDetails(int productId) {
    Product product = null;
    try {
      Connection connection = DriverManager.getConnection(dbUrl, dbUserName, dbPassword);
      Statement s = connection.createStatement();
      String sql = "SELECT ProductId, Name, Description, Price FROM Products" +
        " WHERE ProductId=" + Integer.toString(productId);
      ResultSet rs = s.executeQuery(sql);
      if (rs.next()) {
        product = new Product();
        product.id = rs.getInt(1);
        product.name = rs.getString(2);
        product.description = rs.getString(3);
        product.price = rs.getDouble(4);
      }
      rs.close();
      s.close();
      connection.close();
    }
    catch (SQLException e) {}
    return product;
  }
 
  public boolean insertOrder(String contactName, String deliveryAddress,
    String ccName, String ccNumber, String ccExpiryDate, Hashtable shoppingCart) {
    boolean returnValue = false;
    long orderId = System.currentTimeMillis();
    Connection connection = null;
    try {
      connection = DriverManager.getConnection(dbUrl, dbUserName, dbPassword);
      connection.setAutoCommit(false);
      Statement s = connection.createStatement();
      String sql = "INSERT INTO Orders" +
        " (OrderId, ContactName, DeliveryAddress, CCName, CCNumber, CCExpiryDate)" +
        " VALUES" +
        " (" + orderId + ",'" + contactName + "','" + deliveryAddress + "'," +
        "'" + ccName + "','" + ccNumber + "','" + ccExpiryDate + "')";
      s.executeUpdate(sql);
      // now insert items into OrderDetails table
      Enumeration enumer = shoppingCart.elements();
      while (enumer.hasMoreElements()) {
        ShoppingItem item = (ShoppingItem) enumer.nextElement();
        sql = "INSERT INTO OrderDetails (OrderId, ProductId, Quantity, Price)" +
        " VALUES (" + orderId + "," + item.productId + "," +
        item.quantity + "," + item.price + ")";
        s.executeUpdate(sql);
      }
 
      s.close();
      connection.commit();
      connection.close();
      returnValue = true;
    }
    catch (SQLException e) {
      try {
        connection.rollback();
        connection.close();
      }
      catch (SQLException se) {}
    }
    return returnValue;
  }
}

Open in new window

0
monica73174
Asked:
monica73174
  • 4
  • 2
1 Solution
 
CEHJCommented:
That's a *warning* not an error. It will only fail to compile if there are actual errors, in which case, please post them
0
 
monica73174Author Commented:
When I compile it right in the directory I get these errors below.  But all the files are in the same directory in the burnaby package.  

C:\Tomcat 6.0\webapps\burnaby\WEB-INF\classes\com\brainysoftware\burnaby\DbBean.java:92: cannot find symbol
symbol  : class Product
location: class com.brainysoftware.burnaby.DbBean
  public Product getProductDetails(int productId) {
         ^
C:\Tomcat 6.0\webapps\burnaby\WEB-INF\classes\com\brainysoftware\burnaby\DbBean.java:53: cannot find symbol
symbol  : class Product
location: class com.brainysoftware.burnaby.DbBean
        Product product = new Product();
        ^
C:\Tomcat 6.0\webapps\burnaby\WEB-INF\classes\com\brainysoftware\burnaby\DbBean.java:53: cannot find symbol
symbol  : class Product
location: class com.brainysoftware.burnaby.DbBean
        Product product = new Product();
                              ^
C:\Tomcat 6.0\webapps\burnaby\WEB-INF\classes\com\brainysoftware\burnaby\DbBean.java:77: cannot find symbol
symbol  : class Product
location: class com.brainysoftware.burnaby.DbBean
        Product product = new Product();
        ^
C:\Tomcat 6.0\webapps\burnaby\WEB-INF\classes\com\brainysoftware\burnaby\DbBean.java:77: cannot find symbol
symbol  : class Product
location: class com.brainysoftware.burnaby.DbBean
        Product product = new Product();
                              ^
C:\Tomcat 6.0\webapps\burnaby\WEB-INF\classes\com\brainysoftware\burnaby\DbBean.java:93: cannot find symbol
symbol  : class Product
location: class com.brainysoftware.burnaby.DbBean
    Product product = null;
    ^
C:\Tomcat 6.0\webapps\burnaby\WEB-INF\classes\com\brainysoftware\burnaby\DbBean.java:101: cannot find symbol
symbol  : class Product
location: class com.brainysoftware.burnaby.DbBean
        product = new Product();
                      ^
C:\Tomcat 6.0\webapps\burnaby\WEB-INF\classes\com\brainysoftware\burnaby\DbBean.java:133: cannot find symbol
symbol  : class ShoppingItem
location: class com.brainysoftware.burnaby.DbBean
        ShoppingItem item = (ShoppingItem) enumer.nextElement();
        ^
C:\Tomcat 6.0\webapps\burnaby\WEB-INF\classes\com\brainysoftware\burnaby\DbBean.java:133: cannot find symbol
symbol  : class ShoppingItem
location: class com.brainysoftware.burnaby.DbBean
        ShoppingItem item = (ShoppingItem) enumer.nextElement();
                             ^
Note: C:\Tomcat 6.0\webapps\burnaby\WEB-INF\classes\com\brainysoftware\burnaby\DbBean.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
0
 
CEHJCommented:
You need to have the dependencies (Product and ShoppingItem) on the classpath
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
objectsCommented:
add C:\Tomcat 6.0\webapps\burnaby\WEB-INF\classes to your classpath

0
 
objectsCommented:
java -classpath "C:\Tomcat 6.0\webapps\burnaby\WEB-INF\classes;%CLASSPATH%" .....
0
 
CEHJCommented:
You need to do the following:
javac -classpath C:\Tomcat 6.0\webapps\burnaby\WEB-INF\classes C:\Tomcat 6.0\webapps\burnaby\WEB-INF\classes\com\brainysoftware\burnaby\DbBean.java

Open in new window

0
 
CEHJCommented:
?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now