Solved

JDBC: Database access; Access denied for user

Posted on 2004-08-03
2
762 Views
Last Modified: 2008-01-09
From terminal window I'm able to access my database using:
mysql -u rmwijage -p
Password NahumCh1.

From JDBC when using my database handler I get the following error message:

SQLException: Invalid authorization specification,  message from server: "Access denied for user: 'rrugemalira@localhost.localdomain' (Using password: YES)"
SQLState: 28000
VendorError: 1045

Here is my database handler:
/* ==================================================== */
package rtpm.EAKServlets;

import java.io.*;
import java.net.*;

import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import java.sql.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import rtpmEAKBeans.FormBean;

public class DBHandler extends HttpServlet {

    public void doPost (HttpServletRequest request,
      HttpServletResponse response) {
      try { // OBTAIN A DATABASE CONNECTION
         
          // Step 1: Load the JDBC driver          
          Class.forName("com.mysql.jdbc.Driver");
             
          // Step 2: Establish a connection to the database          
       
          Connection conn = DriverManager.getConnection(
          "jdbc:mysql://localhost/rtpmKenyaDB","rmwijage", "NahumCh1");
 
          String sql = "INSERT INTO rtpm_user(firstname, surname, " +
          "username, password1, password2, email, " +
          "sdp_code) VALUES (?, ?, ?, ?, ?, ?, ?)";
          PreparedStatement ps = conn.prepareStatement(sql);
         
          // Retreave the bean properties to be inserted into table rtpm_user
          FormBean f = (FormBean) request.getAttribute("formHandler");
         
          // Set the parameters in the prepared statement
          ps.setString(1, f.getFirstName());
          ps.setString(2, f.getLastName());
          ps.setString(3, f.getUserName());
          ps.setString(4, f.getPassword1());
          ps.setString(5, f.getPassword2());
          ps.setString(6, f.getEmail());
          ps.setString(7, f.getSdp());
         
          // Insert the row in the table
          ps.executeUpdate();

          // Close the connection
          ps.close();
          conn.close();    
      }
      catch (SQLException e) {
          // handle any errors
          System.out.println("SQLException: " + e.getMessage());
          System.out.println("SQLState: " + e.getSQLState());
          System.out.println("VendorError: " + e.getErrorCode());
          }
      catch (Exception e) {
      e.printStackTrace();
      }
     
      // Send the request back to success.jsp  
      try {
          getServletConfig().getServletContext().
            getRequestDispatcher("/success.jsp").
             forward(request, response);
      }
      catch (Exception e){}
     
   }
}
/* ========================================================================= */

// I do appreciate your kind help.
0
Comment
Question by:Rrugemalira
2 Comments
 
LVL 11

Accepted Solution

by:
sompol_kiatkamolchai earned 500 total points
ID: 11711715
I think it is privileges problem. Please make sure that you already grant permission for this user to insert on that table.
You can use MySQL Administrator to do that

User Administration --> (select user) --> Schema Privileges  --> (select schema) --> Assiged Privileges

Download this tool from

http://dev.mysql.com/downloads/administrator/

0
 
LVL 4

Expert Comment

by:Oliver_Dornauf
ID: 11714844
Did you read the error message?
User rrugemalira@localhost.localdomain can not login, at the console you use rrugemalira@localhost.
Try a diffrent syntax for your connection:

 Connection conn = DriverManager.getConnection(
          "jdbc:mysql://localhost/rtpmKenyaDB?user=rmwijage","rmwijage", "NahumCh1");


check also if you have a typo : rmwijage and rrugemalira
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
JspWriter.write() and JspWriter.print() 4 81
ajax auto save 15 98
lessBy10  challenge 15 92
How can I   ajax html table  rows? 20 62
Scenario: Your operations manager has discovered an anomaly in your security system. The business will start to suffer within 15 minutes if it is a major IT incident. What should she do? We have 6 recommendations for managing major incidents (https:…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

910 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now