allelopath
asked on
MySQLSyntaxException with INSERT statement
This gives a MySQLSyntaxErrorException: You have an error in your SQL syntax message:;
String sqlString = "INSERT INTO myTable VALUES ('1010421', 'null')";
int val = statement.executeUpdate(sq lString);
What is wrong?
String sqlString = "INSERT INTO myTable VALUES ('1010421', 'null')";
int val = statement.executeUpdate(sq
What is wrong?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Maybe a numeric column? Try
String sqlString = "INSERT INTO myTable VALUES (1010421, null)";
String sqlString = "INSERT INTO myTable VALUES (1010421, null)";
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
executeUpdate() is for any sort of query that doesn't return results, which includes INSERT, UPDATE, DELETE and even things like ALTER TABLE. executeQuery() returns a ResultSet and is used for SELECT statements.
did utry angelIII's suggestion?
INSERT INTO myTable ( col1, col2 ) values ('1010421', null)
(replacing col1 and col2 with your column names
and also try it thru mysql directly
INSERT INTO myTable ( col1, col2 ) values ('1010421', null)
(replacing col1 and col2 with your column names
and also try it thru mysql directly
ASKER
desc myTable;
says that the table doesn't exist.
In the terminal, I do a "use mydb"
but I have no equivalent in the java code (and so, perhaps the table is not being created
in the database I think it is)
Do i need a "use db" statement in the Java code?
says that the table doesn't exist.
In the terminal, I do a "use mydb"
but I have no equivalent in the java code (and so, perhaps the table is not being created
in the database I think it is)
Do i need a "use db" statement in the Java code?
problems with your comnnection string.
you need to specify the correct database in your comnnection string
you need to specify the correct database in your comnnection string
or u could try:
INSERT INTO dbname.myTable ( col1, col2 ) values ('1010421', null)
but i'd recomend a different connection string to deal with different databases.
INSERT INTO dbname.myTable ( col1, col2 ) values ('1010421', null)
but i'd recomend a different connection string to deal with different databases.
ASKER
I have Connection connection = DriverManager.getConnectio n(url, user, password);
where url is:
private String url = "jdbc:mysql://localhost:33 06/mysql";
What are the parts of this String, ie what is the database?
where url is:
private String url = "jdbc:mysql://localhost:33
What are the parts of this String, ie what is the database?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
:-)
It's not necessary to specify the column names unless you're using fewer values than you have columns
It's not necessary to specify the column names unless you're using fewer values than you have columns
ASKER
I don't see a method called executeInsert()