Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: java.sql.SQLException: Access denied

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default java.sql.SQLException: Access denied

    I am getting an error from my Spring web application. I am trying to post to my MariaDB database, but I'm getting the following exception.

    org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLSyntaxErrorException: Access denied for user 'ghscom_frank'@'localhost' to database 'ghscom_frank'
    Model object must not be null

    The trouble is that ghscom_root is not the user name I have in my applicationContext.xml. I'm not sure what more information to give, so let me put down a whole lot, and I'm sure if someone needs more they'll ask. Here is the relevant portion of applicationContext.xml.

    	<bean id="dataSource"
    		class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    		<property name="driverClassName" value="com.mysql.cj.jdbc.Driver" />
    		<property name="url" value="jdbc:mysql://localhost/ghscom_ghs86" />
    		<property name="username" value="ghscom_frank" />
    		<property name="password" value="GHSMatadors1986" />
    	</bean>

    This is from my controller.
    	public String writeComment(@ModelAttribute("name") String name,
    			@ModelAttribute("comment") String commentString, Model model) {
    		Calendar date = Calendar.getInstance();
    		Comment comment = new Comment();
    		comment.setName(name.trim());
    		comment.setComment(prepareCommentForDatabase(commentString));
    		comment.setCommentDate(((date.get(Calendar.MONTH) + 1) + "/"
    				+ date.get(Calendar.DATE) + "/" + date.get(Calendar.YEAR)));
     
    		try {
    			commentDAO.writeComment(comment);
    			List<Comment> comments = commentDAO.getComments();
    			model.addAttribute(comments);
    		} catch (Exception e) {
    			System.out.println(e.getMessage());
    			return "Oops";
    		}
     
    		return "GuestBook";
    	}

    This is from my DAO class.
    	public boolean writeComment(Comment comment) {
    		boolean successfulWrite;
    		Calendar date = Calendar.getInstance();
    		comment.setName(comment.getName().trim());
    		comment.setComment(comment.getComment().trim());
    		comment.setCommentDate(((date.get(Calendar.MONTH) + 1) + "/"
    				+ date.get(Calendar.DATE) + "/" + date.get(Calendar.YEAR)));
     
    		try {
    			this.getJdbcTemplate().update(
    					"insert into comments(comment_date, name, comment) values ('"
    							+ comment.getCommentDate() + "', '" + comment.getName()
    							+ "', '" + comment.getComment() + "')");
     
    			successfulWrite = true;
    		} catch (Exception e) {
    			System.out.println(e.toString());
    			successfulWrite = false;
    		}
     
    		return successfulWrite;
    	}

    I have also tried granting privilege to the correct user, but I get the following:
    MariaDB [(none)]> grant all on ghscom_ghs86 to ghscom_frank;
    ERROR 1046 (3D000): No database selected
    Last edited by FHSerkland; October 14th, 2017 at 10:10 PM. Reason: Made edits, error changed

  2. #2
    Junior Member
    Join Date
    Apr 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: java.sql.SQLException: Access denied

    This issue is fixed. I made some fixes to applicationContext.xml and servlet.xml files. I'm not sure what I did, but this works now.

  3. #3

    Default Re: java.sql.SQLException: Access denied

    Solution is to remove data folder from following location.

    Cocuments and SettingsAll/ UsersApplication /DataMySQL

    This directory contains temp files and old DB data including your last login credentials used in previous installation. So, to solve this issue:

    Uninstall MYSQL server
    Remove everything from above folder
    Install a fresh MySQL server[COLOR="Silver"]

Similar Threads

  1. SQL statement is not executed! java.sql.SQLException: General error
    By ppz in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 20th, 2014, 05:36 PM
  2. java.sql.SQLException: No data found
    By Virender in forum JDBC & Databases
    Replies: 2
    Last Post: December 7th, 2011, 01:17 PM
  3. Replies: 1
    Last Post: September 9th, 2011, 02:30 PM
  4. Replies: 0
    Last Post: December 18th, 2010, 08:08 AM
  5. Replies: 6
    Last Post: August 18th, 2010, 05:41 PM

Tags for this Thread