Re: Problem with executing "source ..." query
Posted by: Mark Matthews
Date: May 08, 2005 07:17AM

Jozic wrote:
> Hi all,
> I have a problem with executing sql query from
> java.
> I'm using mysql 4.1.9 and jdk 5.0 on Windows XP.
> I need to pass source file to mysql from java.
> When I do it from mysql console, it works fine.
> "mysql> source U:/myfile.sql;"
> But when I try to do it from java, I get following
> exception:
> "java.sql.SQLException: 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 U:/myfile.sql' at line 1"
> Executing other queries from java (for example
> "create database test1") works as it should be.
> Please, help me if you can... :)
> Thanks.


"source" is a command built-in to the "mysql" command-line client. Other clients such as JDBC, ODBC, Perl, PHP and .Net do not have the capability since they for the most part just pass your query text to the server. You will have to write something similar yourself in Java and use FileInputStream to read the file and send it to Statement.execute().


Mark Matthews
Consulting Member Technical Staff - MySQL Enterprise Tools

Options: ReplyQuote

Written By
Re: Problem with executing "source ..." query
May 08, 2005 07:17AM

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.