[CONJ-238] Problem with MariaDB-java-client-1.3.3.jar and PreparedStatement Created: 2015-12-29  Updated: 2016-06-26  Resolved: 2015-12-31

Status: Closed
Project: MariaDB Connector/J
Component/s: Other
Affects Version/s: 1.3.3
Fix Version/s: 1.3.4

Type: Bug Priority: Major
Reporter: Régis Augui Assignee: Diego Dupin
Resolution: Fixed Votes: 0
Labels: None
Environment:

Os : CentOS Linux release 7.2.1511 (Core)
Java : openjdk version "1.8.0_65"
OpenJDK Runtime Environment (build 1.8.0_65-b17)
OpenJDK 64-Bit Server VM (build 25.65-b01, mixed mode)
Jdbc : mariadb-java-client-1.3.3.jar
mysql-connector-java-5.1.38-bin.jar
MariaDB : Server version: 10.1.10-MariaDB MariaDB Server



 Description   

Hi,

The following example works well with mysql-connector-java-5.1.38-bin.jar
but not with MariaDB-java-client-1.3.3.jar

Here is the error:
java.sql.SQLSyntaxErrorException: Error preparing query: Unknown column 'TMP.alerte_code' in 'field list'
at org.mariadb.jdbc.internal.util.ExceptionMapper.get(ExceptionMapper.java:125)
at org.mariadb.jdbc.internal.util.ExceptionMapper.throwException(ExceptionMapper.java:69)
at org.mariadb.jdbc.MariaDbServerPreparedStatement.prepare(MariaDbServerPreparedStatement.java:117)
at org.mariadb.jdbc.MariaDbServerPreparedStatement.<init>(MariaDbServerPreparedStatement.java:87)
at org.mariadb.jdbc.MariaDbConnection.internalPrepareStatement(MariaDbConnection.java:375)
at org.mariadb.jdbc.MariaDbConnection.prepareStatement(MariaDbConnection.java:222)
at org.rfa.test.FirstExample.main(FirstExample.java:30)
Caused by: org.mariadb.jdbc.internal.util.dao.QueryException: Error preparing query: Unknown column 'TMP.alerte_code' in 'field list'
at org.mariadb.jdbc.internal.protocol.AbstractQueryProtocol.prepare(AbstractQueryProtocol.java:152)
at org.mariadb.jdbc.MariaDbServerPreparedStatement.prepare(MariaDbServerPreparedStatement.java:99)
... 4 more

Thanks

example :

import java.sql.*;
 
public class FirstExample {
    static final String JDBC_DRIVER = "org.mariadb.jdbc.Driver";
    static final String DB_URL = "jdbc:mariadb://localhost:3306/Test";
 
//  static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";  
//  static final String DB_URL = "jdbc:mysql://localhost:3306/WearPdm";
 
    static final String USER = "test";
    static final String PASS = "test";
 
    static final String _SQL =
        "insert into alerte ( alerte_code, alerte_libelle_court, alerte_libelle_long )" +
        "select  TMP.alerte_code, TMP.alerte_libelle_court, TMP.alerte_libelle_long " +
        "from    ( " +
        "select  ? alerte_code, ? alerte_libelle_court, ? alerte_libelle_long " +
        "from   dual " +
        ") TMP";
 
    public static void main(String[] args) {
        Connection conn = null;
        PreparedStatement stmt = null;
        try {
            Class.forName(JDBC_DRIVER);
            conn = DriverManager.getConnection(DB_URL,USER,PASS);
            stmt = conn.prepareStatement(_SQL);
            stmt.setString(1, "test");
            stmt.setString(2, "test");
            stmt.setString(3, "test");
            stmt.executeUpdate();
            stmt.close();
            conn.close();
        } catch(SQLException se) {
            se.printStackTrace();
        } catch(Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if(stmt!=null) stmt.close();
            } catch(SQLException se2){ }
            try {
                if(conn!=null) conn.close();
            } catch(SQLException se) {
                se.printStackTrace();
            }
        }
    }
}



 Comments   
Comment by Diego Dupin [ 2015-12-29 ]

Bug reproduced.

First thought is that Driver must handle insert ... select request differently (client prepared, not server), but to be checked.
Urgent correction in v1.3.4

Comment by Diego Dupin [ 2015-12-31 ]

Specific queries cannot be prepare on server side. For this specific case, use Client preparation.
commit: https://github.com/MariaDB/mariadb-connector-j/commit/8cb011c644aa8c9a678441b35c706639ca67c1c0

Comment by Diego Dupin [ 2016-06-26 ]

Problem concern the unknown "?" parameter
example that doesn't work :

select  TMP.field1 from (select ? `field1` from dual) TMP

Casting correct the behaviour :

select  TMP.field1 from (select CAST(? as binary) `field1` from dual) TMP

Generated at Thu Feb 08 03:14:11 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.