I cannot find any method like
char c = 'c';
preparedStatement.setChar(1, c);
How to set character to a prepared statement?
symbol, which is known as the parameter marker. You must supply values for every parameter before executing the SQL statement. The setXXX() methods bind values to the parameters, where XXX represents the Java data type of the value you wish to bind to the input parameter.
Create a Statement: From the connection interface, you can create the object for this interface. It is generally used for general–purpose access to databases and is useful while using static SQL statements at runtime. Syntax: Statement statement = connection.
The PreparedStatement interface extends the Statement interface it represents a precompiled SQL statement which can be executed multiple times. This accepts parameterized SQL quires and you can pass 0 or more parameters to this query.
The JDBC Specification 4.0 in Appendix B (Data Type Conversion Tables) states the following conversions:
This table also shows the conversions used by the SQLInput reader methods, except that they use only the recommended conversions.
JDBC Type Java Type ------------------------------------------- CHAR String VARCHAR String LONGVARCHAR String NUMERIC java.math.BigDecimal DECIMAL java.math.BigDecimal BIT boolean BOOLEAN boolean TINYINT byte SMALLINT short
TABLE B- 1 JDBC Types Mapped to Java Types
Therefore PreparedStatement.setString(1, String.valueOf(myChar))
should do the trick.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With