[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2007-10-04
4
Medium Priority
?
1,631 Views
Last Modified: 2013-12-10
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
0
Comment
Question by:alnasl
  • 3
4 Comments
 
LVL 20

Expert Comment

by:gatorvip
ID: 20014694
>>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");
]

0
 

Author Comment

by:alnasl
ID: 20015337
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?
0
 

Author Comment

by:alnasl
ID: 20015407
i tried that. it made no difference. same error.
>:-(
0
 

Accepted Solution

by:
alnasl earned 0 total points
ID: 20019991
ok i got it! it worked when i created a new user in myrealm.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most of the developers using Tomcat find it easy to configure the datasource in Server.xml and use the JNDI name in the code to get the connection.  So the default connection pool using DBCP (or any other framework) is made available and the life go…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month20 days, 6 hours left to enroll

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question