Re: database toolbox problem



I have found a workaround for this problem.

This bug is already listed in the Matlab bug reports and
currently there is no solution available.

Searching the net I have found some hints for a workaround
using the jdbc connector.

WORKAROUND-------------------------

import java.lang.Thread
import java.lang.Class
import java.sql.DriverManager

current_thread = java.lang.Thread.currentThread();
class_loader = current_thread.getContextClassLoader();
class = java.lang.Class.forName('com.mysql.jdbc.Driver',
true, class_loader);
database_url = 'jdbc:mysql://localhost/seismon';
conn = java.sql.DriverManager.getConnection(database_url,
'seismon', 'seismon');
stmt = conn.createStatement();

query = 'ALTER TABLE test ADD test_col VARCHAR(10) NOT NULL';
result = stmt.execute(query);

% % This command produces the know error message:
% result = stmt.executeQuery(query);

-----------------------------------


The workaround is based on the following solution of a mysql
bug report:

"The JDBC spec states that you must either use
Statement.executeUpdate() or Statement.execute() for queries
that manipulate data (such as your 'UPDATE documents SET
web_exp....' query).

Older versions of the JDBC driver were more lax on this.
However, it is important to be
JDBC-compliant, so the later versions of the driver enforce
this requirement."

The coding is taken from:
http://www.mathworks.com/matlabcentral/newsreader/view_thread/161242

Until later,
Stefan.


"Stefan " <jo@xxxxxxxxx> wrote in message
<fqm5m9$lfh$1@xxxxxxxxxxxxxxxxxx>...
Hello,

I have a problem using the database toolbox exec function.

I'd like to add columns to a table. Using the jdbc connector
and the command exec(conn, query) results in the following
error:

'Can not issue data manipulation statements with
executeQuery().'

I have read on the mysql homepage, that this error occurs
with the jdbc connector when using the wrong java command:

"The JDBC spec states that you must either use
Statement.executeUpdate() or
Statement.execute() for queries that manipulate data (such
as your 'UPDATE documents SET
web_exp....' query).

Older versions of the JDBC driver were more lax on this.
However, it is important to be
JDBC-compliant, so the later versions of the driver enforce
this requirement."

Here is my code:

conn =

database('datasourcename','username','password','com.mysql.jdbc.Driver',
'jdbc:mysql://localhost/dbUrl');
query = 'ALTER TABLE test ADD type VARCHAR(10) NOT NULL
AFTER id, ADD domain VARCHAR(45) NOT NULL';
curs = exec(conn, curQuery);


The query works when using the mysql command line.

Is there a way to solve this problem in matlab?

Best regards,
Stefan.

.



Relevant Pages

  • Re: why excute query through JDBC much slow than query analyzer?
    ... why excute query through JDBC much slow than query analyzer? ... The SendStringParametersAsUnicode is a connection string attribute that is ... If you capture the Execution Plan in a SQL Profiler trace while executing ...
    (microsoft.public.sqlserver.jdbcdriver)
  • Re: Setting Query Timeout through JDBC (CA Driver problem?)
    ... I suggest to you not using commands like ""set lockmode ..." ... inside jdbc because they are not intended for being used like that nor ... About query timeout we have not used it, but I do not remember any ...
    (comp.databases.ingres)
  • Re: JDBC / ODBC problem
    ... surprised if you find bugs in databases, JDBC or ODBC drivers. ... Do the query differently. ...
    (comp.lang.java.programmer)
  • Re: SQL Developer - Selects
    ... JDBC offers to set the maximum number of rows returned by the query, and I assume that SQL Developer is using that feature - especially as you cannot see any limits when you trace the statement. ... My assumption is that the JDBC driver only sends the defined limit to the server, and the server is able to take this into account when returning the result. ...
    (comp.databases.oracle.server)
  • Re: number of rows in a resultset
    ... > JDBC allows the driver to read the results in chunks. ... > If your ResultSet isn't scrollable, then you have to walk through it: ... Also, maybe the first query could be an SQL "count", and the second query ... and as I am no SQL expert I have no idea if it would provide any ...
    (comp.lang.java.programmer)