?
Solved

-Xlint:unchecked warning, File will not compile.

Posted on 2009-02-15
7
Medium Priority
?
419 Views
Last Modified: 2012-05-06
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
Comment
Question by:monica73174
  • 4
  • 2
7 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 23647549
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
 

Author Comment

by:monica73174
ID: 23647567
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 23647581
You need to have the dependencies (Product and ShoppingItem) on the classpath
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 92

Accepted Solution

by:
objects earned 2000 total points
ID: 23647585
add C:\Tomcat 6.0\webapps\burnaby\WEB-INF\classes to your classpath

0
 
LVL 92

Expert Comment

by:objects
ID: 23647586
java -classpath "C:\Tomcat 6.0\webapps\burnaby\WEB-INF\classes;%CLASSPATH%" .....
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 23647607
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 23647684
?
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Suggested Courses
Course of the Month15 days, 21 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question