When using PreparedStatement
's setObject
method for a column of type TEXT (in a MySQL DB), what should the last parameter be?
For example, I know that this is ok for a VARCHAR column:
stmt.setObject(i, "bla", Types.VARCHAR);
where stmt
is a PreparedStatement
, and Types
is java.sql.Types
.
But if the DB column's type is TEXT, should I still use VARCHAR? or maybe BLOB, or CLOB?
MySQL provides connectivity for client applications developed in the Java programming language with MySQL Connector/J. Connector/J implements the Java Database Connectivity (JDBC) API, as well as a number of value-adding extensions of it. It also supports the new X DevAPI.
In Java, we can connect to our database(MySQL) with JDBC(Java Database Connectivity) through the Java code. JDBC is one of the standard APIs for database connectivity, using it we can easily run our query, statement, and also fetch data from the database.
The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type INTEGER . The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type JAVA_OBJECT .
The answer (YES, you are meant to use VARCHAR) can be found here:
http://dev.mysql.com/doc/connector-j/en/connector-j-reference-type-conversions.html (updated outdated broken link)
and here is some info about the MYSQL TEXT
type
http://dev.mysql.com/doc/refman/5.0/en/blob.html
Why you don't use
stmt.setString ?
for text type ? http://download.oracle.com/javase/1.4.2/docs/api/java/sql/PreparedStatement.html#setString(int, java.lang.String)
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