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