Hi,
your SQL is correct but the code isn't. You are expecting a column called
"data_type_id" because most likely you're doing this after the resultset:
rs.getString("data_type_id");
This column is only used in the where clause.
What you should do instead is something like this:
String sql =
"SELECT AsWKT(point_type) AS point_wkt " +
"FROM point_types " +
"WHERE data_type_id = 2";
ResultSet rs = sqlStatement.executeQuery(sql);
while (rs.next()) {
String wkt = rs.getString("point_wkt");
}
Le jeu. 29 janv. 2026 à 05:52, danap via discuss <[email protected]>
a écrit :
> GIVEN:
> -------------------------------------
> -- Ajqvue SQL Dump
> --
> -- Host: 127.0.0.1
> -- Generated On: 2026.01.28 AD at 05:46:57 MST
> -- SQL version: MariaDB 12.1.2-MariaDB-log
> -- JDBC Connector: JDBC 3.5.7.
> -- Database: mariadbtypes
> -- ------------------------------------------
> -- Table structure for table `point_types`
> --
>
> CREATE TABLE `point_types` (
> `data_type_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
> `point_type` point DEFAULT NULL,
> PRIMARY KEY (`data_type_id`)
> ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4
> COLLATE=utf8mb4_unicode_ci;
>
> INSERT INTO point_types
> (point_type)
> VALUES
> (PointFromText('POINT(10 10)')),
> (PointFromText('POINT(20 20)'));
> ------------------------------------------------
>
> Can anyone explain to me what is wrong with the following SQLStatement?
>
> StringBuffer sqlStatementString = new StringBuffer();
> sqlStatementString.append("SELECT AsWKT(`point_type`) FROM `point_types`
> WHERE `data_type_id`='2'");
> ResultSet db_resultSet =
> sqlStatement.executeQuery(sqlStatementString.toString());
>
> TableTabPanel actionPerformed() (CM) Connection Created
> TableTabPanel_MariaDB viewSelectedItem()
> SQLException: Unknown label 'data_type_id'. Possible value
> [aswkt(`point_type`), .aswkt(`point_type`)]
> SQLState: null
> VendorError: 0
> TableTabPanel actionPerformed() (CM) Connection Closed
>
> It executes fine in the command line tool:
> MariaDB [mariadbtypes]> SELECT AsWKT(`point_type`) FROM `point_types`
> WHERE `data_type_id`='2';
>
> +---------------------+
> | AsWKT(`point_type`) |
> +---------------------+
> | POINT(20 20) |
> +---------------------+
> 1 row in set (0.001 sec)
>
> MariaDB [mariadbtypes]>
> _______________________________________________
> discuss mailing list -- [email protected]
> To unsubscribe send an email to [email protected]
>
_______________________________________________
discuss mailing list -- [email protected]
To unsubscribe send an email to [email protected]