0 Replies Latest reply on Oct 21, 2015 5:30 AM by PeterValencic

    QR code generator (if someone need it)

    PeterValencic

      Hi,

      here is my version of QRcode generator with java stored procedure and plsql.

       

      1.) Download java librarires from this url: https://drive.google.com/open?id=0B6Z9wNTXyUEeV0VmaDN0MEpxa2s

      2.) unzip jar files into some folder ex:  c:\jars

      3.) with load java tool upload each jar file into database with: loadjava -force -genmissing -r -user username/password@database -verbose [jarfilename]

      4.) Here is java stored procedure to generate QRcode with some text:

      CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED "QRCodeBean" as
      
      
      import oracle.sql.BLOB;  
      import oracle.sql.*;  
      import oracle.jdbc.driver.*;  
      import java.sql.*;  
      import javax.imageio.ImageIO;  
      import java.awt.image.BufferedImage;  
      import java.io.ByteArrayOutputStream;  
      import java.io.File;  
      import java.io.FileOutputStream;  
      import java.io.OutputStream; 
      import java.io.*;
      import java.util.*;
      import net.glxn.qrgen.QRCode;
      import net.glxn.qrgen.image.ImageType; 
      
      
      public class QRCodeGenerator{  
      
      
      public static BLOB getQrCode(String value) throws Exception  
      {  
          OracleDriver ora = new OracleDriver();  
          Connection conn = ora.defaultConnection();  
          BLOB retBlob = BLOB.createTemporary(conn, true, oracle.sql.BLOB.DURATION_SESSION);  
        
                  ByteArrayOutputStream out = new ByteArrayOutputStream();
                  out = net.glxn.qrgen.QRCode.from(value).to(ImageType.GIF).stream();
                    
                  try {  
                      java.io.OutputStream outStr = retBlob.setBinaryStream(0);  
                      outStr.write(out.toByteArray());  
                      outStr.flush();  
                  } finally {  
                      out.close();  
                  }  
                 return retBlob;  
      }  
      }
      /
      

       

      5.) Here is the plsql functio which call java stored procedure

       

      CREATE OR REPLACE function getQRcode(p_text in varchar2) return BLOB as LANGUAGE JAVA  
      NAME 'QRCodeGenerator.getQrCode(java.lang.String) return oracle.sql.BLOB';
      /
      

       

      6.) You can execute the function with:  select getQRcode('sometext') from dual;

      The function will return blob field with a QRCode in GIF format...

       

      QR2.jpg