I wrote this code where when the software starts it takes data from a database (MYSQL control center) and bring them to a table. But when I compile this code 2 errors occurs.
Note: C:\Users\Commander Shepard\Documents\NetBeansProjects\Furniture Management System\src\furnituremanagementsystem\employee.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
My Code:
public class employee extends javax.swing.JFrame {
// Creates new form employee
public employee() {
initComponents();
Date now = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd");
datelabel.setText(formatter.format(now));
try {
Statement s = DB.getConnection().createStatement();
DefaultTableModel dtm = (DefaultTableModel) jTable1.getModel();
dtm.setRowCount(0);
ResultSet r = s.executeQuery("SELECT * from Employee");
while (r.next()) {
Vector v = new Vector();
v.add(r.getString(1));
v.add(r.getString(2));
v.add(r.getString(3));
v.add(r.getString(4));
v.add(r.getString(5));
v.add(r.getString(6));
v.add(r.getString(7));
v.add(r.getString(8));
v.add(r.getString(9));
v.add(r.getString(10));
v.add(r.getString(11));
v.add(r.getString(12));
v.add(r.getString(13));
v.add(r.getString(14));
dtm.addRow(v);
}
} catch (Exception e) {
e.printStackTrace();
}
}
@SuppressWarnings("unchecked")
...
}
The thing didn't actually affect the program, it's working properly, but I want to know if this is going to be a problem in the future and whether I should do something about this.
By "recompile with -Xlint", the compiler means to inform you that you need to recompile your program like this: javac -Xlint abc.java. If you do so, the compiler will tell you which methods are deprecated so you can remove your calls to them.
How to resolve warning message: uses or overrides a deprecated api. You can resolve this warning message by using recommned API. In our example, we should use setVisible(true) rather than show() method.
The javac -Xlint options control warnings for all files compiled in a particular run of javac . You may have identified specific locations in source code that generate warnings that you no longer want to see. You can use the @SuppressWarnings annotation to suppress warnings whenever that code is compiled.
That happens when you use generic references. You don't really need to take the warning into consideration, but if you want to see what it is you should compile again with the new argument:
javac programname.java argument
But using generics in Java has many problems as it was added quite late and with all the backward compatibility issues, yeah, we don't need to get into that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With