Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the java.sql.Types equivalent for the MySQL TEXT?

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?

like image 336
Eran Zimmerman Gonen Avatar asked Jul 21 '11 07:07

Eran Zimmerman Gonen


People also ask

What is Java MySQL?

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.

Is MySQL used in Java?

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.

What is Java SQL types integer?

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 .


2 Answers

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

like image 75
Kevin Burton Avatar answered Sep 20 '22 12:09

Kevin Burton


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)

like image 27
Vivek Goel Avatar answered Sep 19 '22 12:09

Vivek Goel