
I have a class file AbstractDataAccessObject with the below code.
package com.dts.core.dao;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
import com.dts.core.util.LoggerManager;
public class AbstractDataAccessObject
{
public Connection mCon;
private static Properties mProps;
/**
* @return the props
*/
public Properties getProperties()
{
return mProps;
}
/**
* @param props
* application properties object
*/
public void setProperties(Properties aProps)
{
mProps = aProps;
}
public Connection getConnection()
{
try
{
Properties aProps = getProperties();
System.out.println(aProps.getProperty("driver"));
Class.forName(aProps.getProperty("driver"));
mCon = DriverManager.getConnection(aProps.getProperty("url"), aProps.getProperty("duser"), aProps.getProperty("dpass"));
System.out.println(mCon);
}
catch (ClassNotFoundException cnfe)
{
LoggerManager.writeLogWarning(cnfe);
}
catch (SQLException se)
{
LoggerManager.writeLogWarning(se);
}
return mCon;
}
/* public Connection getConnection(String cp)
{
try
{
Properties aProps = getProperties();
Class.forName( aProps.getProperty("driver") );
String JNDI = aProps.getProperty("JNDI_NAME");
try
{
InitialContext ictx = new InitialContext();
DataSource ds = (DataSource) ictx.lookup(JNDI);
mCon = ds.getConnection();
}
catch (NamingException ne)
{
LoggerManager.writeLogWarning(ne);
}
}
catch (ClassNotFoundException cnfe)
{
LoggerManager.writeLogWarning(cnfe);
}
catch (SQLException se)
{
LoggerManager.writeLogWarning(se);
}
return mCon;
}*/
public int getSequenceID(String tableName, String pkid)
{
int id = 0;
try
{
mCon = getConnection();
Statement st = mCon.createStatement();
ResultSet rs = st.executeQuery("select max("+pkid+") from "+tableName);
if(rs.next())
id=rs.getInt(1);
id++;
}
catch(SQLException se)
{
LoggerManager.writeLogWarning(se);
}
catch(Exception e)
{
LoggerManager.writeLogWarning(e);
}
finally
{
try
{
mCon.close();
}
catch(SQLException se)
{
LoggerManager.writeLogWarning(se);
}
catch(Exception e)
{
LoggerManager.writeLogWarning(e);
}
}
return id;
}
}
The data for the connection to the database is specified in the Web-inf >> config >>system.properties.
The code is as follows
# Sample ResourceBundle properties file JNDI_NAME=java:com/env/Oracle/jndi db.login= db.password= driver=oracle.jdbc.driver.OracleDriver url=jdbc:oracle:thin:@192.168.100.20:1521:server duser=ware dpass=ware logfile=E:/log/warehouse_log.txt dbname=oracle
Let me know what is the duser and dpass.. ? I have created a new user from oracle sql*plus as rajalakshmi and password by granting privilege from scott and tiger. should I use the duser and dpass as rajalakshmi and password for duser and dpass.. or scott and tiger.
But nothing of the duser and dpass works.
If I use it also, unable to connect to backend oracle database.
Let me know what is db.username and db.password? should I leave it blank ?