Dear my friends... I tried this singelton pattern. But I got this error message: === patrixlinux@patrix:~/arsip/My/coba-2x/1> javac Connector.java Connector.java:2: cannot resolve symbol symbol : class Connection location: class Connector private static Connection conn; ^ Connector.java:18: cannot resolve symbol symbol : class Connection location: class Connector public static Connection getConnection() { ^ Connector.java:7: cannot resolve symbol symbol : variable DriverManager location: class Connector conn = DriverManager.getConnection("jdbc:mysql://localhost/amt?user=root&password=pandawa5"); ^ Connector.java:12: cannot resolve symbol symbol : class SQLException location: class Connector } catch (SQLException sqle) { ^ Connector.java:31: cannot resolve symbol symbol : class SQLException location: class Connector } catch (SQLException sqle) { ^ Connector.java:41: cannot resolve symbol symbol : class PreparedStatement location: class Menu PreparedStatement ps = null; ^ Connector.java:44: cannot resolve symbol symbol : class Connection location: class Menu Connection con = Connector.getConnection(); ^ Connector.java:47: cannot resolve symbol symbol : class SQLException location: class Menu } catch (SQLException sqle) { ^ Connector.java:51: cannot resolve symbol symbol : class SQLException location: class Menu } catch (SQLException sqle) { ^ 9 errors patrixlinux@patrix:~/arsip/My/coba-2x/1> === And here is my simple code: === public class Connector { private static Connection conn; private Connector() { try { Class.forName("com.mysql.jdbc.Driver"); conn = DriverManager.getConnection("jdbc:mysql://localhost/amt?user=root&password=pandawa5"); System.out.println("Connected"); } catch (ClassNotFoundException cnfe) { cnfe.printStackTrace(); } catch (SQLException sqle) { sqle.printStackTrace(); } } // Connection akan di-inisial sekali saja. public static Connection getConnection() { if (conn == null) { new Connector(); } return conn; } public static void closeConnection() { if (conn != null) { try { conn.close(); System.out.println("Disconnected"); } catch (SQLException sqle) { sqle.printStackTrace(); } } } } class Menu { //.... public static void customer() { PreparedStatement ps = null; try { Connection con = Connector.getConnection(); ps = con.prepareStatement("SELECT customerid FROM customer"); //..... } catch (SQLException sqle) { } finally { try { if (ps != null) ps.close(); } catch (SQLException sqle) { } } } } === Anybody would be so nice to teach me, please.... __________________________________ Do you Yahoo!? New Yahoo! Photos - easier uploading and sharing. http://photos.yahoo.com/
Hi,
* Prabu Subroto
private Connector() {
^^^^^^^^^
public static Connection getConnection() {
^^^^^^^^^^ See the difference? You should brush up the basics a bit. The error message is a plain indicator that some variable was unknown to the compiler. That is usually (with me anyway) some import issue or a typo. Thorsten -- A 'No' uttered from deepest conviction is better and greater than a 'Yes' merely uttered to please, or what is worse, to avoid trouble. - Mahatma Gandhi
Hi,
* Thorsten Haude
Hi,
* Prabu Subroto
[2003-12-15 16:31]: private Connector() {
^^^^^^^^^
public static Connection getConnection() {
^^^^^^^^^^ See the difference?
I see it now. Sorry for the confusion. Thorsten -- The true danger is when liberty is nibbled away for expedients. - Edmund Burke
[...] Connector.java:2: cannot resolve symbol symbol : class Connection location: class Connector private static Connection conn; ^ [...] ^ Connector.java:12: cannot resolve symbol symbol : class SQLException location: class Connector } catch (SQLException sqle) { ^ [...]
import java.sql.*; -- Regards, Alex
Solved....Thanks my friend...
--- Alexander Veit wrote:
[...] Connector.java:2: cannot resolve symbol symbol : class Connection location: class Connector private static Connection conn; ^ [...] ^ Connector.java:12: cannot resolve symbol symbol : class SQLException location: class Connector } catch (SQLException sqle) { ^ [...]
import java.sql.*;
-- Regards, Alex
-- To unsubscribe, email: suse-programming-e-unsubscribe@suse.com For additional commands, email: suse-programming-e-help@suse.com Archives can be found at: http://lists.suse.com/archive/suse-programming-e
__________________________________ Do you Yahoo!? New Yahoo! Photos - easier uploading and sharing. http://photos.yahoo.com/
participants (4)
-
Alexander Veit
-
Prabu Subroto
-
Thorsten Haude
-
Victor R. Cardona