can anyone help me with this issue, i'm working with java using SQLMap(ibatis). i have 3 class which is MainConfiguration, SQLMap, DBUtility.
- Main Configuration (this class is using to set an object inside SQLMap class)
public class MainConfiguration
{
public static String file = "configuration/db/SQLMapConfig.conf";
public static void main(String[] args) throws Exception
{
new MainConfiguration().loadConfiguration();
}
public static void loadConfiguration()
{
SQLMap.setMapFile(file);
List list = DBUtility.loadUsers();
}
}
- SQL Map (this class is the getter and setter of and object)
public final class SQLMap
{
private static SqlMapClient sqlMap;
public static void setMapFile(String sMapFile)
{
try
{
sqlMap = SqlMapClientBuilder.buildSqlMapClient(new FileReader(sMapFile));
}
catch (Exception e)
{
throw new RuntimeException("Error initializing SqlMapClient class", e);
}
}
public static SqlMapClient getSqlMapInstance()
{
return sqlMap;
}
}
DBUtility (this class is where object instance and get object from SQLMap class)
public class DBUtility { // object utility protected static SqlMapClient sqlMap = SQLMap.getSqlMapInstance(); //constructor public DBUtility() throws Exception { } public static List loadUsers() { //it's working logger.info("SQLMap Get Instance = " + SQLMap.getSqlMapInstance()); //it's not working logger.info("SQLMap Get Instance = " + sqlMap); //code below will be error because of null sqlMap try { listUser = sqlMap.queryForList("getUsers"); } catch (Exception sqle) { logger.error("Error on load all user", sqle); } return listUser; } }
the logger give me this :
SQLMap Get Instance = com.ibatis.sqlmap.engine.impl.SqlMapClientImpl@76707e36
SQLMap Get Instance = null
how come the second log give me null, even i have instance the object?