English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

would like to know,

is it better to put a connectionstring (called from a static method from another class) into a string variable, and pass the string to the methods, or get the connectionstring (call the static method) in every methods that requires it?


//==================================
//SAMPLE 1
//==================================

public static void Main()
{
string strConn = ConnectionString.GetConnectionString();

AA(strConn);

if (VV())
{
BB(strConn);
}
}


//=================================
//SAMPLE 2
//=================================

public static void Main()
{
Preprocessing();

if (VV())
{
PopulateUIData();
}
}

private static void AA()
{
string strConn = ConnectionString.GetConnectionString();

}

private static void BB()
{
string strConn = ConnectionString.GetConnectionString();

2007-01-01 17:17:12 · 3 answers · asked by Anonymous in Computers & Internet Programming & Design

3 answers

There does not seem to be too great a difference in both codes . Check out Java Documentation on Sun Website to find out if they have mentioned anything on this .

2007-01-01 18:12:19 · answer #1 · answered by Anonymous · 0 0

Well it depends if this function or method is going to be used multiple times then I suggest to use option #1 Call the method from another class.

If the call of this method if this is only one time call then go option #2 Call method everytime is required. You can also make use of this method/Class for other program use ...

Good Luck

2007-01-02 02:39:54 · answer #2 · answered by Anonymous · 0 0

Actually, it would be better if you keep the connection open and use the pass the connection variable around.

2007-01-02 01:20:44 · answer #3 · answered by Kasey C 7 · 1 0

fedest.com, questions and answers