If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > jdbc creating new database error mystifying

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-23-03, 16:33
yorkedork yorkedork is offline
Registered User
 
Join Date: Nov 2003
Posts: 2
Angry jdbc creating new database error mystifying

Hello all,

I am using Tomcat 5.0.9 and Mysql 4-0-14 which are running on a Sun/Solaris server. I have had both up and running for quite some time. I use databases to store information that is extracted to dynamically create a web app. To store/update/extract the information contained in these databases, there is an administration tool which serves this role. On one of the JSPs there is a form to create a new database which sends relevant data to a bean which handles the connections.

To create a new database, I use JDBC to connect to a dummy database. The following code is what I use to do so:


Connection connect =
DriverManager.getConnection("jdbc:mysql:///"
+ "dummy" + "?user=" + userName +
"&password=" + password);

Statement stmt = connect.createStatement();
String create = new String( "create database " +
databaseName );
stmt.execute( create );
stmt.close();


/* try connecting to the new database */
connect = DriverManager.getConnection("jdbc:mysql:///"
+ databaseName + "?user=" + userName +
"&password=" + password);

stmt = connect.createStatement();

/* create an empty database */
String script = new String(
"source/home/webapps/mysql/scripts/createTables.sql" );

boolean check = stmt.execute( script );


When the user requests a new database, error messages are displayed at the bottom of the page, and I get

"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 'source /home/webapps/mysql/scripts/createTables.sql' at line 1"

I know that there are no errors in the script, because I can use mysql -u root -p -D <<databaseName>> to connect
and source the script and everything works fine.

Any ideas would be greatly appreciated.

Thanks.
Reply With Quote
  #2 (permalink)  
Old 11-23-03, 16:37
yorkedork yorkedork is offline
Registered User
 
Join Date: Nov 2003
Posts: 2
clarification

In my code, there *is* a space between source and the directory in the following statement.

=> String script = new String( "source /home/webapps/mysql/scripts/createTables.sql" );
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On