Statement and ResultSet (first try / new bie)
Dear my friends... I have some problems in compiling my code. Please tell me where the mistakes... Here is the error message : psubroto@susefujitsu:~/arsip/proyek> javac LoadDriver.java LoadDriver.java:29: cannot resolve symbol symbol : class Statement location: class LoadDriver Statement stmt = null; ^ LoadDriver.java:30: cannot resolve symbol symbol : class ResultSet location: class LoadDriver ResultSet rs = null; ^ 2 errors psubroto@susefujitsu:~/arsip/proyek> And this is my code: ==== import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; // Notice, do not import com.mysql.jdbc.* // or you will have problems! public class LoadDriver { public static void main(String[] args) { try { // The newInstance() call is a work around for some // broken Java implementations Class.forName("com.mysql.jdbc.Driver").newInstance(); System.out.println("The driver was loaded succesfully."); } catch (Exception ex) { // handle the error System.out.println("The driver could not be loaded."); } try { Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/amt?user=root&password=prabumas"); // Do something with the Connection System.out.println("Connection has been built"); // Doing select Query // assume conn is an already created JDBC connection Statement stmt = null; ResultSet rs = null; try { stmt = conn.createStatement(); rs = stmt.executeQuery("SELECT foo FROM bar"); // or alternatively, if you don't know ahead of time that // the query will be a SELECT... if (stmt.execute("SELECT foo FROM bar")) { rs = stmt.getResultSet(); } // Now do something with the ResultSet .... } finally { // it is a good idea to release // resources in a finally{} block // in reverse-order of their creation // if they are no-longer needed if (rs != null) { try { rs.close(); } catch (SQLException sqlEx) { // ignore } rs = null; } } if (stmt != null) { try { stmt.close(); } catch (SQLException sqlEx) { // ignore } stmt = null; } } } } catch (SQLException ex) { // handle any errors System.out.println("SQLException: " + ex.getMessage()); System.out.println("SQLState: " + ex.getSQLState()); System.out.println("VendorError: " + ex.getErrorCode()); } } } __________________________________ Do you Yahoo!? SBC Yahoo! DSL - Now only $29.95 per month! http://sbc.yahoo.com
Hi, * Prabu Subroto <prabu_subroto@yahoo.com> [2003-07-08 22:21]:
psubroto@susefujitsu:~/arsip/proyek> javac LoadDriver.java LoadDriver.java:29: cannot resolve symbol symbol : class Statement location: class LoadDriver Statement stmt = null; ^ LoadDriver.java:30: cannot resolve symbol symbol : class ResultSet location: class LoadDriver ResultSet rs = null; ^ 2 errors psubroto@susefujitsu:~/arsip/proyek>
And this is my code: ==== import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; (...)
I'm too lazy to look it up, but I doubt that Statement or ResultSet are in java.lang. You must import them. Thorsten -- When bad men combine, the good must associate; else they will fall one by one, an unpitied sacrifice in a contemptible struggle. - Edmund Burke
Hallo Thorsten... I tried to imported "java.lang.*" but it didn't work. Still the same error message. Here is the error message : " ifirdaus@susefujitsu:~/arsip/proyek> javac LoadDriver.java LoadDriver.java:30: cannot resolve symbol symbol : class Statement location: class LoadDriver Statement stmt = null; ^ LoadDriver.java:31: cannot resolve symbol symbol : class ResultSet location: class LoadDriver ResultSet rs = null; ^ 2 errors ifirdaus@susefujitsu:~/arsip/proyek> " Here is my code: " import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.lang.*; // Notice, do not import com.mysql.jdbc.* // or you will have problems! public class LoadDriver { public static void main(String[] args) { try { // The newInstance() call is a work around for some // broken Java implementations Class.forName("com.mysql.jdbc.Driver").newInstance(); System.out.println("The driver was loaded succesfully."); } catch (Exception ex) { // handle the error System.out.println("The driver could not be loaded."); } try { Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/amt?user=root&password=prabumas"); // Do something with the Connection System.out.println("Connection has been built"); // Doing select Query // assume conn is an already created JDBC connection Statement stmt = null; ResultSet rs = null; " Please teach me... Where the mistake. --- Thorsten Haude <linux@thorstenhau.de> wrote:
Hi,
* Prabu Subroto <prabu_subroto@yahoo.com> [2003-07-08 22:21]:
psubroto@susefujitsu:~/arsip/proyek> javac LoadDriver.java LoadDriver.java:29: cannot resolve symbol symbol : class Statement location: class LoadDriver Statement stmt = null; ^ LoadDriver.java:30: cannot resolve symbol symbol : class ResultSet location: class LoadDriver ResultSet rs = null; ^ 2 errors psubroto@susefujitsu:~/arsip/proyek>
And this is my code: ==== import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; (...)
I'm too lazy to look it up, but I doubt that Statement or ResultSet are in java.lang. You must import them.
Thorsten -- When bad men combine, the good must associate; else they will fall one by one, an unpitied sacrifice in a contemptible struggle. - Edmund Burke
ATTACHMENT part 2 application/pgp-signature
__________________________________ Do you Yahoo!? SBC Yahoo! DSL - Now only $29.95 per month! http://sbc.yahoo.com
Hi, * Prabu Subroto <prabu_subroto@yahoo.com> [2003-07-10 01:06]:
I tried to imported "java.lang.*" but it didn't work.
They are *not* from java.lang. They look like some SQL stuff, but you should really look it up yourself to get a better feel for the packages. Either use the API docs or get Flanagan's 'Java in a Nutshell'. (Good sigmonster, have a cookie.) Thorsten -- A: Top posters Q: What's the most annoying thing about email these days?
participants (2)
-
Prabu Subroto
-
Thorsten Haude