Mailinglist Archive: opensuse-programming (105 mails)
| < Previous | Next > |
Statement and ResultSet (first try / new bie)
- From: Prabu Subroto <prabu_subroto@xxxxxxxxx>
- Date: Tue, 8 Jul 2003 13:21:12 -0700 (PDT)
- Message-id: <20030708202112.28044.qmail@xxxxxxxxxxxxxxxxxxxxxxx>
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
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
| < Previous | Next > |