Newbie Java JDBC Question
Posted by: flatoff
Date: January 09, 2005 10:01PM

Hello - I'm trying to write a sample program to explore the functionality of MySql with Java so I can learn how to write real programs. I haven't done any database programming with Java yet.

I am trying to compile some code and I get some errors:

C:\java\MySql>javac cannot resolve symbol
symbol : class Statement
location: class TestMySql
Statement stmt = null;
^ cannot resolve symbol
symbol : class ResultSet
location: class TestMySql
ResultSet rs = null;
2 errors


Here's the 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 TestMySql{

public static void main(String[] args) {

Statement stmt = null;
ResultSet rs = null;

try {
// The newInstance() call is a work around for some
// broken Java implementations

Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/test?user=root&password=xxxxx");

stmt = conn.createStatement();
rs = stmt.executeQuery("SELECT * FROM mytable");

} catch (SQLException ex) {
// handle any errors
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
catch (Exception ex) {
// handle the error
System.out.println("An error has occured");
} 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 {
} catch (SQLException sqlEx) { // ignore

rs = null;

if (stmt != null) {
try {
} catch (SQLException sqlEx) { // ignore

stmt = null;




Can someone point me in the right direction here?


Options: ReplyQuote

Written By
Newbie Java JDBC Question
January 09, 2005 10:01PM
January 10, 2005 04:15PM
January 12, 2005 09:54PM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.