# Error with executeQuery()

**URL:** <https://forum.inductiveautomation.com/t/error-with-executequery/75954>\
**Category:** Ignition\
**Tags:** ignition81, perspective, database\
**Created:** [July 5, 2023, 6:00pm UTC](https://forum.inductiveautomation.com/t/error-with-executequery/75954 "2023-07-05T18:00:01Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ian.sebryk](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ian.sebryk/32/49319_2.png) [@ian.sebryk](https://forum.inductiveautomation.com/u/ian.sebryk)\
**Post date:** [July 5, 2023, 6:00pm UTC](https://forum.inductiveautomation.com/t/error-with-executequery/75954/1 "2023-07-05T18:00:02Z")

</div>

built a named query to create a test table in database:

```plaintext
create table testUsers (
	id int auto_increment primary key,
	firstName varchar(255) not null,
	lastName varchar(255) not null,
	email varchar(255) not null unique,
	isAdmin boolean,
	canEdit boolean,
	canRead boolean,
	canConfig boolean,
	isNotifified boolean
);

```

running the query from the `Testing` tab returned this error:

```plaintext
com.inductiveautomation.ignition.client.gateway_interface.GatewayException: java.sql.SQLException:
Can not issue data manipulation statements with executeQuery().

```

now before you get excited, this will eventually become broken out into a bitwise permission table and a general user table. that aside, my query is fine (i ran it on the db in [Heidi](https://www.heidisql.com) to be sure), so why does it throw an error? the irony is that i'm following the IU tutorial on Creating Tables... i've just modified my query to reflect something useful to me and closed my query properly.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [July 5, 2023, 6:02pm UTC](https://forum.inductiveautomation.com/t/error-with-executequery/75954/2 "2023-07-05T18:02:55Z")

</div>

Change your named query to be an "update" type.

---

<div class="post-metadata">

**Author:** ![ian.sebryk](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ian.sebryk/32/49319_2.png) [@ian.sebryk](https://forum.inductiveautomation.com/u/ian.sebryk)\
**Post date:** [July 5, 2023, 6:28pm UTC](https://forum.inductiveautomation.com/t/error-with-executequery/75954/3 "2023-07-05T18:28:44Z")

</div>

okaayyy... RTFM = nothing about `create` falling into the `Update Query` category found. why differentiate 'query types'? the query itself has everything you need and returns what you ask for: entire dataset or single datum.

IU _does_ indicate the correct type; i must have glazed over that, so i apologize. i am very familiar with SQL so it never occurred to me that queries would ever be differentiated like this.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [July 5, 2023, 6:30pm UTC](https://forum.inductiveautomation.com/t/error-with-executequery/75954/4 "2023-07-05T18:30:27Z")

</div>

> [@ian.sebryk](#):
>
> i am very familiar with SQL so it never occurred to me that queries would ever be differentiated like this.

JDBC requirement.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [July 5, 2023, 6:34pm UTC](https://forum.inductiveautomation.com/t/error-with-executequery/75954/5 "2023-07-05T18:34:19Z")

</div>

> [@ian.sebryk](#):
>
> nothing about `create` falling into the `Update Query` category found

Basically any query that results in a change to the Database is an Update Query.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [July 5, 2023, 6:43pm UTC](https://forum.inductiveautomation.com/t/error-with-executequery/75954/6 "2023-07-05T18:43:49Z")

</div>

> [@pturmel](#):
>
> JDBC requirement.

To expand on this a little bit...

> [@ian.sebryk](#):
>
> the query itself has everything you need and returns what you ask for: entire dataset or single datum.

Java, the language, has no idea what a SQL query is, nor what type it is. So you're essentially giving a random string to a random method on a random object. Java has no ability to do multiple return types, nor sealed classes or generics (20 years ago when the JDBC spec was written, at least). So the only way to disambiguate and get a programmatically useful return type from the method call was to add two different method types:  
[https://docs.oracle.com/en/java/javase/11/docs/api/java.sql/java/sql/Statement.html#executeQuery(java.lang.String)](https://docs.oracle.com/en/java/javase/11/docs/api/java.sql/java/sql/Statement.html#executeQuery(java.lang.String))  
[https://docs.oracle.com/en/java/javase/11/docs/api/java.sql/java/sql/Statement.html#executeUpdate(java.lang.String)](https://docs.oracle.com/en/java/javase/11/docs/api/java.sql/java/sql/Statement.html#executeUpdate(java.lang.String))

It would be nice if this could be caught by Ignition and displayed as a more friendly error... but it's just a standard Java SQLException, so the only way for Ignition to distinguish it from "your SQL was wrong" or any of a huge variety of other possible SQL errors is by checking the string error message of the code...which is also subject to localization by the JVM. Thus, the current state of affairs, where you get a technically correct, but nearly useless error message unless you know all this extra context.

---

<div class="post-metadata">

**Author:** ![ian.sebryk](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ian.sebryk/32/49319_2.png) [@ian.sebryk](https://forum.inductiveautomation.com/u/ian.sebryk)\
**Post date:** [July 5, 2023, 6:48pm UTC](https://forum.inductiveautomation.com/t/error-with-executequery/75954/7 "2023-07-05T18:48:58Z")

</div>

@paul-griffith THAT was a very useful reply. i am NOT familiar with Java and to that end the JDBC. makes sense now. and thanks twice for taking the time to educate. i like to know WHY. now i get to ask a question how to import 10000 records QUICKLY... look for it soon. 😃

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [July 5, 2023, 6:52pm UTC](https://forum.inductiveautomation.com/t/error-with-executequery/75954/8 "2023-07-05T18:52:05Z")

</div>

> [@ian.sebryk](#):
>
> how to import 10000 records QUICKLY

See this topic for one technique:

> [@Using Gateway scripts to move data from one database to another](https://forum.inductiveautomation.com/t/using-gateway-scripts-to-move-data-from-one-database-to-another/75953/5):
>
> This, handed to system.db.runPrepUpdate(), will insert three rows at once: INSERT INTO some\_table (some\_column1, some\_column2, some\_column3) VALUES (?, ?, ?), (?, ?, ?), (?, ?, ?) You would provide the nine arguments in a flat list. You would construct the SQL dynamically with the right number of inserted row placeholders and the right number of JDBC substitution arguments. Just be careful not to exceed the limit on ? placeholders. Some JDBC drivers choke at around 2000.

---

<div class="post-metadata">

**Author:** ![ian.sebryk](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ian.sebryk/32/49319_2.png) [@ian.sebryk](https://forum.inductiveautomation.com/u/ian.sebryk)\
**Post date:** [July 5, 2023, 6:54pm UTC](https://forum.inductiveautomation.com/t/error-with-executequery/75954/9 "2023-07-05T18:54:37Z")

</div>

ooh-la! sweet! 💯 🥳 thanks @pturmel! reading that now
