Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deprecation with JAVAC

Status
Not open for further replies.

munnanext

Programmer
Aug 20, 2004
49
US
What is Deprecation option and when we have to use this in compiling the JAVA Files ?

I have a JAVA Program and when I compile this it is asking me to cpile using Deprecation option.When I compile this it is giving me the following Warning.

C:\suresh\Java\myPackage>javac -deprecation myJDBC.java
myJDBC.java:43: warning: setLogStream(java.io.PrintStream) in java.sql.DriverMa
ager has been deprecated
DriverManager.setLogStream(System.out);

Source:

package myPackage;
import java.net.URL;
import java.sql.*;

class SimpleSelect {


public static void main (String args[]) {
String url = "jdbc:eek:dbc:Xtreme";
String query = "SELECT * FROM Purchases";

try {

// Load the jdbc-odbc bridge driver

Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");

DriverManager.setLogStream(System.out);

// Attempt to connect to a driver. Each one
// of the registered drivers will be loaded until
// one is found that can process this URL

Connection con = DriverManager.getConnection (
url, "my-user", "my-passwd");

// If we were unable to connect, an exception
// would have been thrown. So, if we get here,
// we are successfully connected to the URL

// Check for, and display and warnings generated
// by the connect.

checkForWarning (con.getWarnings ());

// Get the DatabaseMetaData object and display
// some information about the connection

DatabaseMetaData dma = con.getMetaData ();

System.out.println("\nConnected to " + dma.getURL());
System.out.println("Driver " +
dma.getDriverName());
System.out.println("Version " +
dma.getDriverVersion());
System.out.println("");

// Create a Statement object so we can submit
// SQL statements to the driver

Statement stmt = con.createStatement ();

// Submit a query, creating a ResultSet object

ResultSet rs = stmt.executeQuery (query);

// Display all columns and rows from the result set

dispResultSet (rs);

// Close the result set

rs.close();

// Close the statement

stmt.close();

// Close the connection

con.close();
}
catch (SQLException ex) {

// A SQLException was generated. Catch it and
// display the error information. Note that there
// could be multiple error objects chained
// together

System.out.println ("\n*** SQLException caught ***\n");

while (ex != null) {
System.out.println ("SQLState: " +
ex.getSQLState ());
System.out.println ("Message: " + ex.getMessage ());
System.out.println ("Vendor: " +
ex.getErrorCode ());
ex = ex.getNextException ();
System.out.println ("");
}
}
catch (java.lang.Exception ex) {

// Got some other type of exception. Dump it.

ex.printStackTrace ();
}
}

//-------------------------------------------------------------------
// checkForWarning
// Checks for and displays warnings. Returns true if a warning
// existed
//-------------------------------------------------------------------

private static boolean checkForWarning (SQLWarning warn)
throws SQLException {
boolean rc = false;

// If a SQLWarning object was given, display the
// warning messages. Note that there could be
// multiple warnings chained together

if (warn != null) {
System.out.println ("\n *** Warning ***\n");
rc = true;
while (warn != null) {
System.out.println ("SQLState: " +
warn.getSQLState ());
System.out.println ("Message: " +
warn.getMessage ());
System.out.println ("Vendor: " +
warn.getErrorCode ());
System.out.println ("");
warn = warn.getNextWarning ();
}
}
return rc;
}

//-------------------------------------------------------------------
// dispResultSet
// Displays all columns and rows in the given result set
//-------------------------------------------------------------------

private static void dispResultSet (ResultSet rs)
throws SQLException
{
int i;

// Get the ResultSetMetaData. This will be used for
// the column headings

ResultSetMetaData rsmd = rs.getMetaData ();

// Get the number of columns in the result set

int numCols = rsmd.getColumnCount ();

// Display column headings

for (i=1; i<=numCols; i++) {
if (i > 1) System.out.print(",");
System.out.print(rsmd.getColumnLabel(i));
}
System.out.println("");

// Display data, fetching until end of the result set

boolean more = rs.next ();
while (more) {

// Loop through each column, getting the
// column data and displaying

for (i=1; i<=numCols; i++) {
if (i > 1) System.out.print(",");
System.out.print(rs.getString(i));
}
System.out.println("");

// Fetch the next result set row

more = rs.next ();
}
}

}

Would apprecaite if you could tell me what for this error and what needs to be done to resolve this.

Thanks


 
A deprecated method is one in which Sun has considered the method to be outdated, and usually has replaced with a better method.
It means your code will compile & run fine, but in the future, you should use another method, because in future releases, the method could be removed.

--------------------------------------------------
Free Database Connection Pooling Software
 
Normally, if you have a deprecation, it is a good idea to dig a little around in their documentation - somewhere it will be described why it is deprecated.

In this case, it is suggested that you use the DriverManager's setLogWriter function, because the LogStream, as its JavaDoc points out, should not be used where characters and not bytes are used.

The documentation is rather obscure in some cases though, I don't know why they didn't write that into the setLogStream's documentation itself...

By the way, I coulnd't link to the functions themselves, the Tek-Tips parser quits parsing hyperlinks at braces.

haslo@haslo.ch - www.haslo.ch​
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top