Link to home
Start Free TrialLog in
Avatar of alnasl
alnasl

asked on

SQL Exception #1: java.sql.SQLException: User: qqrtcb, failed to be authenticated.

Hi!

I am new to this, so don't be too harsh ;-)
I'm invoking a servlet, that is supposed to build only a connection to a database and I get the error:

SQL Exception #1: java.sql.SQLException: User: qqrtcb, failed to be authenticated.

The server is remote. I have a sqlplus client on my computer and I am accessing the database manually without problems, using a username, password and a connect string - uname/passwd@connect_string. The username and the passowrd are the same as those I am using in the servlet.
-------------------------------------------------------------------------------------
Here's the code:

package trip;

import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import javax.sql.*;
import javax.naming.*;

public class TestDataSource extends HttpServlet
{
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, java.io.IOException
{
res.setContentType("text/html");
java.io.PrintWriter pick = new java.io.PrintWriter(res.getOutputStream());
try
{
Context ctx = new InitialContext();
if(ctx == null)
{
pick.println("JNDI problem. Can't get InitialContext. <br>");
}
else
{
pick.println("Road goes ever on, over rock and under tree<br>");
}
try
{
DataSource ds = (DataSource)ctx.lookup("jdbc/puck");
if(ds == null)
{
pick.println("One ring to rule them all...<br>" );
}
else
{
pick.println("Much that once was, is now lost!<br>");
}
try{
Connection con = ds.getConnection("qqrtcb", "bmw");
con.setAutoCommit(false);
                                   
PreparedStatement pstmt = con.prepareStatement("SELECT id, name FROM stechnologies;");
                                   
ResultSet rs = pstmt.executeQuery();
if(rs != null)
{
pick.println("Frodo! It's Frodo Baggins!");
while(rs.next())
{
String id  = rs.getString(1);
String name = rs.getString(2);
pick.println(id + " ; ; " + name);
}
}
else
{
pick.println("...and in the darkness bind them!");
}
rs.close();
pstmt.close();
con.close();
}
catch(SQLException sqle2)
{
pick.println("SQL Exception #1: " + sqle2 + "<br>");
}
                       
}
catch(NamingException ne)
{
pick.println("<b>Naming Exception #1: </b>" + ne + "<br>");
}
}                  
catch(NamingException ne)
{
pick.println("Naming error #3: " + ne + "<br>");
}
pick.close();            
}
     
public void init(ServletConfig cfg)
throws ServletException
{
super.init(cfg);
}

public void destroy()
{
super.destroy();
}
}
----------------------------------------------------------------------------------------------------------------------------
The whole output that I get in the browser looks like that:

Road goes ever on, over rock and under tree
Much that once was, is now lost!
SQL Exception #1: java.sql.SQLException: User: qqrtcb, failed to be authenticated.
--------------------------------------------------------------------------------------------------------------------------
What do I do wrong?

any help would be greatly appreciated.

oh, and i forgot!

I've created the connection pool and the datasource in the WebLogic Administrator Console. So in my opinion they shouldn't be a problem.

thanks once more in advance.

al
Avatar of gatorvip
gatorvip
Flag of United States of America image

>>Connection con = ds.getConnection("qqrtcb", "bmw");

Looks like your problem lays right here. You're not getting a connection to the database.

[
Context ctx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup("jdbc/puck");
]

Avatar of alnasl
alnasl

ASKER

aye, that's exactly what i thought. but then, it works, when I do it in sqlplus. same username and password.

the code is full of try statements, so that i could narrow the error possibilities. and this is the only line, that could be faulty. but I don't see how.

what do you mean with these lines:

Context ctx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup("jdbc/puck");

I don't see a difference to mine. do you mean, that I should pack the both lines in one try... catch block?
Avatar of alnasl

ASKER

i tried that. it made no difference. same error.
>:-(
ASKER CERTIFIED SOLUTION
Avatar of alnasl
alnasl

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial