Platforms to show: All Mac Windows Linux Cross-Platform

JavaPreparedStatementMBS class

Superclass: JavaStatementMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
class Java Database MBS Java Plugin 8.5 ✅ Yes ✅ Yes ✅ Yes ❌ No Desktop, Console & Web
An object that represents a precompiled SQL statement.
Example
// query with parameters over JDBC, safe against SQL injection
// conn is a JavaConnectionMBS from JavaDatabaseMBS.getConnection, see there
Var conn As JavaConnectionMBS // your connection
If conn = Nil Then Return

Var statement As JavaPreparedStatementMBS = conn.prepareStatement("SELECT name FROM customers WHERE city = ? AND orders > ?")
statement.setString(1, "Berlin")
statement.setInt(2, 5)

Var rs As JavaResultSetMBS = statement.executeQuery
While rs.NextRecord
System.DebugLog rs.getString(1)
Wend

A SQL statement is precompiled and stored in a PreparedStatement object. This object can then be used to efficiently execute this statement multiple times.

Note: The setter methods (setShort, setString, and so on) for setting IN parameter values must specify types that are compatible with the defined SQL type of the input parameter. For instance, if the IN parameter has SQL type INTEGER, then the method setInt should be used.

If arbitrary parameter type conversions are required, the method setObject should be used with a target SQL type.

In the following example of setting a parameter, con represents an active connection:

PreparedStatement pstmt = con.prepareStatement("UPDATE EMPLOYEES SET SALARY = ? WHERE ID = ?");
pstmt.setBigDecimal(1, 153833.00)
pstmt.setInt(2, 110592)
Subclass of the JavaStatementMBS class.
This is an abstract class. You can't create an instance, but you can get one from various plugin functions.

Superclass JavaStatementMBS

Superclass JavaObjectMBS

Sub classes:

Blog Entries

Release notes

  • Version 26.6
    • Changed JavaCallableStatementMBS class to be subclass of JavaPreparedStatementMBS class.
  • Version 24.4

Some methods using this class:

Some examples using this class:

Some related classes:


The items on this page are in the following plugins: MBS Java Plugin.


JavaParameterMetaDataMBS   -   JavaResultSetMBS


The biggest plugin in space...