database now defined as singleton
This commit is contained in:
12
Database.cs
12
Database.cs
@@ -7,8 +7,9 @@ namespace it_projekt
|
||||
{
|
||||
class Database
|
||||
{
|
||||
private static Database _database;
|
||||
public List<Person> Persons { get; set; }
|
||||
public Database(String username, String password)
|
||||
private Database(String username, String password)
|
||||
{
|
||||
string connectionString = "server=localhost;port=3306;database=stammdaten;User Id=" + username + ";Password=" + password + ";";
|
||||
MySqlConnection connection = new MySqlConnection(connectionString);
|
||||
@@ -36,5 +37,14 @@ namespace it_projekt
|
||||
connection.Close();
|
||||
Console.WriteLine("Done.");
|
||||
}
|
||||
|
||||
public static Database getDatabase(string username, string password)
|
||||
{
|
||||
if (_database == null)
|
||||
{
|
||||
_database = new Database(username, password);
|
||||
}
|
||||
return _database;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user