1
我正在使用jython 2.2.1和jdbc 1.2並連接到一個mssql 2000數據庫,向它寫入一封電子郵件的內容。當我得到可能相當大的電子郵件正文時,有時需要截斷5000個字符的數據。除了mssql & jdbc幫我起來像學校院子裏的惡霸,當我檢查我的數據的數據庫加載丟失,每次,最大字符= 256個字符。JDBC和MSSQL似乎在截斷大字段
我檢查了字段的大小,它被設置爲5000.什麼給出了?
我很確定它是與jdbc相關的,因爲以前的版本使用.... vb6 & odbc,順利。
這裏是一些代碼:
BODY_FIELD_DATABASE=5000
def _execute_insert(self):
try:
self._stmt=self._con.prepareStatement(\
"INSERT INTO EmailHdr (EntryID, MailSubject, MailFrom, MailTo, MailReceive, MailSent, AttachNo, MailBody)\
VALUES (?, ?, ?, ?, ?, ?, ?, cast(? as varchar (" + str(BODY_FIELD_DATABASE) + ")))")
self._stmt.setString(1,self._emailEntryId)
self._stmt.setString(2,self._subject)
self._stmt.setString(3,self._fromWho)
self._stmt.setString(4,self._toWho)
self._stmt.setString(5,self._emailRecv)
self._stmt.setString(6,self._emailSent)
self._stmt.setString(7,str(int(self._attachmentCount) + 1))
self._stmt.setString(8,self._format_email_body())
self._stmt.execute()
self._prepare_inserting_attachment_data()
self._insert_attachment_data()
except:
raise
def _format_email_body(self):
if not self._emailBody:
return " "
if len(self._emailBody) > BODY_FIELD_DATABASE:
return self._clean_body(self._emailBody[:BODY_FIELD_DATABASE])
else:
return self._clean_body(self._emailBody)
def _clean_body(self,dirty):
'''used to clean =20 occurrence in email body that contains chinese characters
http://en.wikipedia.org/wiki/Quoted-printable'''
dirty=str(dirty)
return dirty.replace(r"=20","")
不,在文本中還有空格,並且格式良好,減去= 20s。 – Setori 2008-11-28 02:06:51