Reputation: 2134
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
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