JDBC and MSSQL seem to trim large fields

I am using jython 2.2.1 and jdbc 1.2 and am connecting to mssql 2000 database by writing email content to it. When I get to the body of an email, which can be quite large, sometimes I need to truncate the data by 5000 characters. Except for mssql and jdbc, they attack me like backyard schoolchildren when I check my database load, every time, with max chars = 256 characters.

I checked the field size and set it to 5000. What gives?

I'm pretty sure this has to do with jdbc as the previous version was using ... vb6 and odbc, no hitch.

here is the code:

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","")

      

+1


source to share


1 answer


Deleted my answer - it was completely wrong. Keeping it here, though, so comments and conversation are everywhere.

EDIT:



As you can read in the comments, this is what happened:

The data was put into the database perfectly, but the MSSQL Query Manager was unable to display the Chinese characters.

0


source







All Articles