sweet dreams
sweet dreams

Reputation: 2134

Create table works in MySql but not in JDBC

This works in MySql-

create database CarRentalCo;
use CarRentalCo;
create table LuxuryCars(rate varchar(5));

I tried to do the same thing in java, using jdbc and I got an error-

//Some code here
String query = 
"create database CarRentalCo; "
"use CarRentalCo; "
"create table LuxuryCars(rate varchar(5)); "
//some code here
executeUpdate(query);

Error:

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 'use CarRentalCo; create table LuxuryCars(rate varchar(5))' at line 1

Upvotes: 0

Views: 201

Answers (1)

Michael Simons
Michael Simons

Reputation: 4890

Some jdbc drivers have problems including a ; at the end of the statement, but the main problem is only one statement per executeUpdate.

Also i don't think it's a good idea to change the database connection through a query when you're using jdbc. Should be part of the url connect string.

Upvotes: 2

Related Questions