help in jdbc/jndi/java class



hi
i've created some simple java beans, when i do log in, i forward it to
servlet where i create LoginDTO object from username and password. in
the same class i validate the username and password with the system.
but it returns null value to connection object.


Login.jsp <|------------Loginform(action=LoginServlet)

in LoginServlet, loginDTO is created
loginDTO=new
LoginDTO(req.getParameter("userName"),req.getParameter("password"));

Database class is meant for database operations like connection,
disconnection, insert/validation/deletion.

I do connectivity through Database.connect()

public final class Database{
//declaration of member variables
public static void connect()
{
try
{
ic= new InitialContext();
DataSource
ds=(DataSource)ic.lookup("jdbc/proformaInvoice");
conn=ds.getConnection();
System.out.println("Hello World"); //to check whether
it comes to this line or not.
}
catch(SQLException se){}
catch(NamingException ne){}
}

//this method validates user name and password with the system.
public static boolean validate(LoginDTO loginDTO)
{
boolean bnFlag;
authMap=new HashMap<String,String>();
try
{
stmt=conn.createStatement();
res=stmt.executeQuery("Select User, Password from
UserMaster");
while(res.next())
{

authMap.put(res.getString("user").toUpperCase(),res.getString("password"));
}
if(authMap.containsKey(loginDTO.getName()) &&
authMap.get(loginDTO.getName()).equals(loginDTO.getPassword()))
{
bnFlag=true;
}
else
{
bnFlag=true;
}
}
catch(SQLException se){bnFlag=false;}
return bnFlag;
}


jdbc/proformaInvoice is configured in Java AppServer 9 as jndi name to
derby driver and database name. in App server there is ping facility
that checks whether the configuration done is correct or not, and in my
database, it is pinging, but still it gives null to connection.
Is it because of i'm using datasource in java class context? Do i've
to use normal Class.forName() way to load drivers in memory?

.



Relevant Pages

  • Re: connecting to a database
    ... so I'm attempting to code it up in java. ... I have no idea how to set up a connection. ... connection to an Access Database that they would be willing to post. ... sql. ...
    (comp.lang.java.programmer)
  • Re: connecting to a database
    ... I have no idea how to set up a connection. ... connection to an Access Database that they would be willing to post. ... throws java. ... sql. ...
    (comp.lang.java.programmer)
  • Re: Java and MySql program example ?
    ... > I am trying to learn Java and need an example program with MySql ... > MySql database. ... Database connection established ...
    (comp.lang.java.programmer)
  • java hangs in cron
    ... I have a java program which makes connection to Oracle database to ... If I run this shell script from command line the ...
    (RedHat)
  • Stuff the purple heart programmers cook up
    ... C To act like a framework for the JDBC driver developers. ... D To hide the specifics of accessing particular kinds of database ... Topic: Java 2: Survey Author: Chris Mc Devitt ... The JDBC ResultSet is actually an interface java.sql.ResultSet. ...
    (comp.lang.java.programmer)