This is the code I use:
package blobdatabase;
import java.nio.charset.Charset;
import java.sql.*;
/**
*
* @author Edson Lagamayo
*/
public class Main {
public static void main(String[] args) {
String returnValue = "";
try {
Connection con = null;
System.out.println("character set : " + Charset.defaultCharset());
Class.forName("com.mysql.jdbc.Driver").newInstance();
con = DriverManager.getConnection("jdbc:mysql://192.168.90.52/productiondb?useUnicode=true&characterEncoding=utf-8", "root", "root");
Statement st;
st = con.createStatement();
ResultSet resultSet = st.executeQuery("SELECT imgfilename,field7,field8,field9,field10,field11,field12,field13,field14,field15,field16,field17,field18,field19,field20,field21,field22,field23,remarks1,remarks2,remarks3,remarks4,remarks5,remarks6,remarks7,remarks8,remarks9,remarks10,remarks11,remarks12 FROM (SELECT MAX(stampid) stampid,orderid,projid,jobid,taskcode FROM tstasks t WHERE t.jobid=187 AND taskcode=1 GROUP BY t.orderid)t LEFT JOIN orderdetail od ON od.seqid=t.stampid AND od.orderid=t.o开发者_开发知识库rderid RIGHT JOIN imageinfo ii ON ii.orderid=od.orderid AND ii.projid=t.projid WHERE t.jobid=187;");
while (resultSet.next()) {
Blob blob = resultSet.getBlob("remarks7");
returnValue = blob != null ? new String(blob.getBytes(1, (int) blob.length())) : "";
System.out.println("returnValue : " + returnValue);
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
the output i'm having is :
returnValue : ��4546345435435sdfaf4324324
returnValue : �
returnValue : sdafghbgjbgjnbhgnjbggbvrfsdfsdcvewr54trtgdfg���fdsjdgfdgdgfdfgdgsdafghbgjbgjnbhgnjbggbvrfsdfsdcvewr54trtgdfg���f
�� is sometimes a square the value for this would be ÑÑ can anyone help me with this? please help me solve my problem
:)useUnicode=true&characterEncoding=utf-8
...only tells the driver to blindly assume it's UTF-8. It does NOT set the character encoding of the connection. You should set the default charset to UTF-8 in mysql config, or run the following query right after connection:
SET names utf8
精彩评论