私は、MySQLデータベース内のテーブルからTEXTフィールドの値を取得しようとしています。 MySQLのバージョンは、私は私のファイルは、これは私のコラムはあるが存在しないことを言うResultSetのgetString()メソッドを使用して、MySQLテーブルからTEXT型カラムの値を取得できますか?
import java.sql.*;
public class DatabaseConnection {
static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
static final String DB_URL = "jdbc:mysql://localhost/book";
// database credentials
static final String USER = "username";
static final String PASS = "password";
public static void main(String[] args) {
Connection conn = null;
Statement stmt = null;
try {
Class.forName("com.mysql.jdbc.Driver");
System.out.println("Connecting to database...");
conn = DriverManager.getConnection(DB_URL, USER, PASS);
System.out.println("Creating statement...");
stmt = conn.createStatement();
String query;
query = "Select b_name, description columns from brands";
ResultSet rs = stmt.executeQuery(query);
while(rs.next()) {
String first_name = rs.getString("b_name");
String description = rs.getString("description");
System.out.println(first_name);
System.out.println(description);
}
rs.close();
stmt.close();
conn.close();
} catch(SQLException se) {
se.printStackTrace();
} catch(ClassNotFoundException cnfe) {
cnfe.printStackTrace();
}
finally{
//finally block used to close resources
try{
if(stmt!=null)
stmt.close();
} catch(SQLException se2){
}// nothing we can do
try{
if(conn!=null)
conn.close();
} catch(SQLException se){
se.printStackTrace();
}//end finally try
}//end try
System.out.println("Goodbye!");
}
}
の下に与えられているのmysql-コネクタのjava-5.1.18-bin.jarを
を使用しています5.6.21 &です
をしかし、テーブルはDESCRIPという名前の列があります。私は、このエラーが現れ、それがVARCHAR列ではなく、TEXTカラム上で動作し、別のテーブルの上にこれを試してみました:
MySQL Connector/J 5.1.18はかなり古く(6年)、最新は5.1.42です。アップグレードを検討することをお勧めします。https://dev.mysql.com/downloads/connector/j/ –