Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback, please email oracle-forums_moderators_us@oracle.com

setString can only process strings of less than 32766 chararacters

NTWAug 3 2023

I have a java program which sends an email after processing data from an Oracle table. I did not write this program myself and am not familiar with java code but was able to figure out that my email body is too long for a string variable. Here's what I see in the code. The EmailBody variable is set to a String

public static void main(String[]args)throws IOException {

   String grant\_type       = args\[0\];  
   String client\_id        = args\[1\];  
   String scope            = args\[2\];  
   String client\_secret    = args\[3\];  
   String tokenUrl         = args\[4\];  
   String Content\_Type     = args\[5\];  
   String LandMARC\_user\_id = args\[6\];  
   String plan\_url         = args\[7\];  
   String FileLocation     = args\[8\];  
   String BondsEmail       = args\[9\];          
   String jdbc\_conn\_det    = args\[10\];          
   String ora\_user\_psswd   = args\[11\];  
   String Password         = ora\_user\_psswd.substring(5);  
   String EmailBody        = null;  
   String EmailBody1       = "Here is the status:  " + '\\n' + '\\n';       
   String updJSON          = null;  
   String File\_Name        = null;  
   int PlanUpdCount        = 0;

Later in the logic I have this:

       try {  
           DriverManager.registerDriver(new oracle.jdbc.OracleDriver());

           oracle.jdbc.OracleConnection conn =  
               (oracle.jdbc.OracleConnection)DriverManager.getConnection("jdbc:oracle:oci:@"+jdbc\_conn\_det,"pwd",Password);

           CallableStatement stmt1 = null;  
           stmt1 = conn.prepareCall("{call lcfnd\_util.send\_smtp\_email(p\_from=>:1,p\_to\_recipient=>:2,p\_subject\_line=>:3,p\_body\_text=>:4,x\_return\_status=>:5,x\_msg\_data=>:6)}");

           Statement stmt2 = conn.createStatement();  
           ResultSet rs;  
           rs = stmt2.executeQuery("select name InstanceName from v$pdbs");                

           String InstanceName = null;  
           String FromEmail = null;  
           String ToEmail = null;  
           while (rs.next()) {  
               InstanceName = rs.getString("InstanceName");                  

               if (InstanceName != null && InstanceName.equals("PRD")) {  
                   FromEmail = "xxx\_" + InstanceName + "@xxx.org";  
                   ToEmail = BondsEmail;  
               } else {  
                   FromEmail = "xxx\_" + InstanceName + "@xxx.org";      
                    ToEmail = "xxx@xxx.org";  
               }  
           }

           stmt1.setString(1, FromEmail);  
           stmt1.setString(2, ToEmail);  
           stmt1.setString(3, File\_Name + " --> Plan ID's Status");  
           stmt1.setString(4, EmailBody1 +" File:  "+File\_Name + '\\n' + EmailBody);

and so on. The emails are not getting sent because the EmailBody is too large. I get this error setString can only process strings of less than 32766 chararacters I need to know how to fix this so that the email will get sent. Do I need to import some java besides these?

import java.io. * ;
import java.util. * ;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.net.URL;
import java.net.URLConnection;
import java.net.HttpURLConnection;
import org.json.JSONObject;
import org.json.JSONArray;
import java.text.SimpleDateFormat;
import java.nio.file.*;

Do I need to use a CLOB instead of string? Is there another way to allow the EmailBody to hold more than 32766 characters? Any help would be greatly appreciated.

-NTW

This post has been answered by justsomeone on Aug 5 2023
Jump to Answer
Comments
Post Details
Added on Aug 3 2023
9 comments
416 views