Nehmen Sie eine Verbindung zum Singleton -MusterJava

Java-Forum
Anonymous
 Nehmen Sie eine Verbindung zum Singleton -Muster

Post by Anonymous »

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;
}
}

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post