Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5971565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:32:02+00:00 2026-05-22T20:32:02+00:00

I am trying to access STATIC Variables from one java class to another but

  • 0

I am trying to access STATIC Variables from one java class to another but am not getting the value!

Below are my java classes.

Static Contents, class 1:

package com.globalProperties;
public class GlobalVariables {

static{
    someFunctionName();
}

    private static String SMTP_SERVER = "";
    private static String SMTP_USERNAME = "";
    private static String SMTP_PASSWORD = "";

    private static void someFunctionName(){
         Connection con = null;
         Statement statement = null;
         ResultSet resultset = null;
         LinkedHashMap<String,String> sysParmHashMap = new LinkedHashMap<String, String>();
             con = DatabaseConnection.getDbConnection();
             statement = con.createStatement();
             String queryStr = "SELECT * FROM SMTPCONNECTION";
             resultset = statement.executeQuery(queryStr);
             while(resultset.next()){
                 sysParmHashMap.put(resultset.getString("KEY"), resultset.getString("KEY_VALUE"));
             }

                // First i tried this to set value 
                SMTP_SERVER = sysParmHashMap.get("SMTP_SERVER").trim();
                SMTP_USERNAME = sysParmHashMap.get("SMTP_USERNAME").trim();
                SMTP_PASSWORD = sysParmHashMap.get("SMTP_PASSWORD").trim();

                // Second time, i tried this to set value 
                setSMTP_SERVER(sysParmHashMap.get("SMTP_SERVER").trim());
                setSMTP_USERNAME(sysParmHashMap.get("SMTP_USERNAME").trim());
                setSMTP_PASSWORD(sysParmHashMap.get("SMTP_PASSWORD").trim());


                System.out.println("SMTP_SERVER :" +SMTP_SERVER);
                System.out.println("SMTP_USERNAME :" +SMTP_USERNAME);
                System.out.println("SMTP_PASSWORD :" +SMTP_PASSWORD);
         }

    public static String getSMTP_SERVER() {
        return SMTP_SERVER;
    }

    public static void setSMTP_SERVER(String sMTP_SERVER) {
        SMTP_SERVER = sMTP_SERVER;
    }

    public static String getSMTP_USERNAME() {
        return SMTP_USERNAME;
    }

    public static void setSMTP_USERNAME(String sMTP_USERNAME) {
        SMTP_USERNAME = sMTP_USERNAME;
    }

    public static String getSMTP_PASSWORD() {
        return SMTP_PASSWORD;
    }

    public static void setSMTP_PASSWORD(String sMTP_PASSWORD) {
        SMTP_PASSWORD = sMTP_PASSWORD;
    }

    public static String getGATEWAY_SERVICE_URL() {
        return GATEWAY_SERVICE_URL;
    }

}

Here i want to acess those static variables Class 2:

package com.unilog.sendMails;
import com.globalProperties.GlobalVariables;
improt .... some imports ....;

public class sendEmailTo extends ActionSupport implements ServletResponseAware {


    public String MailContact(){

        String result = "Fail";

    if(Some condition){
      result = sendingEmail(  --  Parameters  --);
        }



    }

    public String sendingEmail(String toAddress,String fromAddress,String mailSubject,String mailBody){
        String result="FAIL";

        // For Below variable am not getting any value they are Empty but not null
            String smtpHost = GlobalVariables.getSMTP_SERVER();  
            final String smtpUserName = GlobalVariables.getSMTP_USERNAME();
        final String smtpPassword = GlobalVariables.getSMTP_PASSWORD();

    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T20:32:02+00:00Added an answer on May 22, 2026 at 8:32 pm

    Issue solved, i was assigning VARIABLE ="" (empty value for static variable in declaration time)

    It was :

     private static String SMTP_SERVER = "";
        private static String SMTP_USERNAME = "";
        private static String SMTP_PASSWORD = "";
    

    Where it was suppose to be like this :

     private static String SMTP_SERVER;
        private static String SMTP_USERNAME;
        private static String SMTP_PASSWORD;
    

    Now its working fine……

    Thank you…..

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to access a static method, but using a variable as the
I'm trying to implement a category of an existing class. There is a static
I need to pass a variable from Admin.java file to index.jsp. I get the
I'm trying to get FlashPunk working in the Flash CS5 IDE (don't ask), and
Aloha, I have a custom control that I need to instantiate from within a
Well I think the title of this question is far to be clear but
I'm trying to add elements to a Powershell variable with Add-Member. I have no
I'd like to know if it's possible to trace access to an array using
I'm in a little over my head here with OOP in actionscript. I've got
I'm adding Android C2DM to a Android library project. I started with the com.google.android.c2dm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.