Question about destructor of database and multiple use access

Suliman via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Jul 28 07:24:16 PDT 2016


class GDB
{
	Config config;
	MySQLDriver driver;
	DataSource ds;
	Connection conn;

	this(Config config)
	{
		this.config = config;
	 	driver = new MySQLDriver();
	 	string[string] params;
	    string url = MySQLDriver.generateUrl("localhost", 3306, 
"geodb");
	    params = MySQLDriver.setUserAndPassword("root", "123");
	    ds = new ConnectionPoolDataSourceImpl(driver, url, params);
		conn = ds.getConnection();
	
	}
	

	void dbInsert(string login, string uploading_date, string 
geometry_type, string data)
	{
	    Statement stmt = conn.createStatement();
		//stmt.executeUpdate("...");
		// some processing of request
		scope(exit) stmt.close(); // closing
	}

	void getIMGsMetadataFromDB(Json request)
	{

	    Statement stmt = conn.createStatement();
      	//stmt.executeWuery("...");
		// some processing of request
		scope(exit) stmt.close(); // closing
	}
	
Is this code is more correct?


More information about the Digitalmars-d-learn mailing list