Nehmen Sie eine Verbindung zum Singleton -Muster

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Nehmen Sie eine Verbindung zum Singleton -Muster

by Anonymous » 29 Apr 2025, 11:57

Meine Aufgabe ist es, eine Verbindung mit JDBC mit dem Singleton -Muster zu erhalten. Ich wollte fragen, ob ich das Muster benutze oder nicht? < /P>

Code: Select all

public class DbUtils {
private static Connection conn = null;
static {
final String DB_URL = "jdbc:mysql://localhost:3306/library";
final String  USER = "root";
final String PASS = "12345";
try {
conn = DriverManager.getConnection(DB_URL, USER, PASS);
} catch (SQLException e) {
throw new RuntimeException(e);
}

System.out.println("Connected to database");
}
public static Connection getConnection() {
return conn;
}
}

Top