I am trying to find the type of data that a column is through the JDBC driver from MYSQL.
The query I am trying to execute is SHOW FIELDS FROM PARAMETERS WHERE FIELD='COLUMN_NAME' through Java and and the exception thrown is a java.sql.SQLException with the following error: Before Start of Result set. I am positive I am executing the same query as the one I am doing through SQL. Is there any other way of retrieving the column type with just the column name
Related
I was using ORACLE JDBC driver all my query and assertions are based on column names. Now I need to use MySQL database instead.
When I will make request, I can see in result are table name and dot in response.
How to remove them?
If event handler, then we need to use SubmitListener.afterSubmit - but I have no idea, how to obtain response, modify it, and return.
JDBC driver config parameter sounds like is not available. I tried the Postgres driver, but not works in MySQL server.
I am trying to remove the parts marked in yellow:
I've been using the connector for a few years now to push and pull data between a MS SQL Server database and a couple different MySQL databases. I set up a Linked Server, then using OPENQUERY I create the views I need and I write my selects, updates, and inserts against those views. Works like a dream.
However, I'm trying to integrate with a new MySQL database built by a vendor which uses the ENUM datatype, which is causing me trouble.
When I try the OPENQUERY I get a weird error:
OLE DB provider 'MSDASQL' for linked server 'MYSQL_DATABASE' returned data that does not match expected data length for column '[MSDASQL].EnumDataField'. The (maximum) expected data length is 10, while the returned data length is 8.
I can fix this by converting the ENUM field to a CHAR in the query and it works ok.
But now I need to insert or update that ENUM field, and I cannot figure out how to do it. If I convert the datatype on the view, I can't use that view to insert or update.
Is there a way for me to work with ENUM fields through the connector? Especially a way for me to do INSERT or UPDATE of an ENUM value?
Brief background of the system:
Using an SSIS package to move data from SQL Server to MySQL.
I use an OLE DB connection to connect to SQL Server.
I use an ODBC Unicode connection to connect to MySQL.
Most of the system works, but I am having a date conversion issue when passing an SSIS Variable into an Execute SQL Task. It attempts insert a date into a table on the MySQL database. I get the following error when trying to enter a date of {1/1/2010 12:00:00 AM}.
"[Execute SQL Task] Error: Executing the query "Insert into ETLDate values(?)" failed with the following error: "[MySQL][ODBC 5.3(w) Driver][mysqld-5.7.22-log]Incorrect datetime value: '-10165-58296-9719 16613:13824:2136' for column 'LastETLDate' at row 1". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly."
The date is consistently '-10165-58296-9719 16613:13824:2136' so I know the value is getting passed correctly, it's just converted or encoded differently. Here is my setup for the parameter.
Some final notes:
I've tried all the other date data types for the parameter and I get the same issue.
I've tried with just a direct insert statement using the parameter and not a stored procedure and I get the same issue.
All data flow tasks that move data (which includes dates) from the SQL Server DB to the MySQL database work fine.
If create a similar stored procedure and table on the SQL Server DB (with updated parameter settings for the OLE DB connection) it works fine.
Any one know why the date is getting passed incorrectly or have a work around for this issue?
I very recently started the process of trying to get a undocumented and poorly designed project under control. After struggling to get the thing built locally, I started running into errors when going through various functionalities.
Most of these problems appear to be a result of MySQL errors due to the way my product is generating Hibernate criteria queries. For example, when doing an autocomplete on the displayName of an object, the criteria query that results from this action is very large. I end up with around 2200 fields to select from around 50 tables. When hibernate attempts to execute this query I get an error:
30-Mar-2018 11:43:07.353 WARNING [http-nio-8080-exec-8] org.hibernate.util.JDBCExceptionReporter.logExceptions SQL Error: 1117, SQLState: HY000
30-Mar-2018 11:43:07.353 SEVERE [http-nio-8080-exec-8] org.hibernate.util.JDBCExceptionReporter.logExceptions Too many columns
[ERROR] 11:43:07 pos.services.HorriblyDefinedObjectAjax - could not execute query
org.hibernate.exception.GenericJDBCException: could not execute query
I turned on general logging for MySQL and obtained the criteria query that is trying to be executed. If I attempt to execute it in MySQLWorkbench I also get the following result:
Error Code: 1117. Too many columns
I've gone to the QA instances of this application and the autocompletes work there, which seems to indicate there is a way that this huge query will execute. Is it possible that I just do not have the right MySQL configurations on?
Currently my sql_mode='NO_ENGINE_SUBSTITUTION', is there anything else I might need to do?
i'm running mysql 5.5 with mysql 5.1.18 connector.
a simple query of style
select * from my_table where column_a in ('aaa','bbb',...) and column b=1;
is executed from within java application. the query returns a resultset of 25k rows, 8 columns in each. while reading the results in while loop
while(rs.next())
{
MyObject c= new MyObject();
c.setA(rs.getString("A"));
c.setB(rs.getString("B"));
c.setC(rs.getString("C"));
...
}
a following exception is thrown, usually during the first loops, but never in the same row:
java.lang.NullPointerException
at com.mysql.jdbc.ResultSetImpl.getStringInternal(ResultSetImpl.java:5720)
at com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java:5570)
at com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java:5610)
i took a look at the source code in ResultSetImpl.java:5720 and i see the following:
switch (metadata.getSQLType())
where metadata is
Field metadata = this.fields[internalColumnIndex];
and getSQLType is a logic-less getter returning an int. what's interesting, is that the same metadata object is called numerous times several lines above with other getters, and throws no exceptions.
btw, there is no problem with the query above while ran directly within mysql.
application runs in aws.
any ideas how to solve this?
thanks.
I ran into this issue, using a Spring Data CrudRepository, retrieving a Stream of results from a MySql database running on AWS RDS, with a moderately convoluted query.
It would also throw at a non-deterministic row, after about 30k rows.
I resolved this issue by annotating the calling method with #Transactional.
Although you're not using JPA, setting up a transaction for your database access may help your issue.
From my experience, this error is a result of locked table while trying to read/write simultaneously from the same table. You need to add a pool for every request or some wait time between every operation to the MySQL.
Related answer as well:
Getting java.sql.SQLException: Operation not allowed after ResultSet closed