MySQLSyntaxErrorException (?)
Posted by: Macamba .
Date: August 07, 2015 02:24AM

Sorry if this is a standard problem. But I'm stumped.

I'm learning to program with the MySQL Connector for Java (5.1.36). While learning I stumbled upon a MySQLSyntaxError Exception. And, as beginner, I can't find the reason.

public void create(Project project) throws IllegalArgumentException, DAOException {
	if (project.getProjectId() != 0) {
		throw new IllegalArgumentException("Project is already created, the project ID is not null.");

	Object[] values = { project.getProjectNumber(), project.getProjectName(), 
			project.getActivity(), project.getPerNumber(),
			toSqlDate(project.getDate()), project.getTime()}; 
	try (Connection connection = daoFactory.getConnection();
		PreparedStatement statement = prepareStatement(connection, 
			SQL_INSERT_PROJECT, true, values);) {
		int affectedRows = statement.executeUpdate();
		if (affectedRows == 0) {
			throw new DAOException("Creating user failed, no rows affected.");
		try (ResultSet generatedKeys = statement.getGeneratedKeys()) {
			if ( {
			} else {
				throw new DAOException("Creating user failed, no generated key obtained.");
	} catch (SQLException e) {
		throw new DAOException(e);

private static final String SQL_INSERT_PROJECT = 
	"INSERT INTO projects (projectnumber, project, activity, per_number, date, time " 
			+ "VALUES (?, ?, ?, ?, ?, ?)";

And finally, toSqlDate is
    public static Date toSqlDate(java.util.Date date) {
    	return (date != null) ? new Date(date.getTime()) : null;

The error I got is:
class - DAOException constructor, com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; 
check the manual that corresponds to your MySQL server version for the right syntax to use near 
'VALUES ('p10001', 'TimeKeeper', 'DAOTest', '100101', '2015-08-05', '05:30:00')' at line 1
Exception in thread "main" java.lang.NullPointerException

Options: ReplyQuote

Written By
MySQLSyntaxErrorException (?)
August 07, 2015 02:24AM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.