1. 程式人生 > >列印報表在ireport怎樣生成一維碼 二維碼

列印報表在ireport怎樣生成一維碼 二維碼

連線資料庫 :將本地資料庫中的連結方式的jar包  ,生成二維碼的zxing.jar,jbar.jar引入ireport

選擇本地資料庫的型別:在jdbc driver裡面選擇

                                            MS SQLServer (net.sourceforge.jtds.jdbc.Driver)

                                            MS SQLServer (com.merant.datadirect.jdbc.sqlserver.SQLServerDriver)

                                            MySQL (org.gjt.mm.mysql.Driver)

                                            MySQL (com.mysql.jdbc.Driver)

                                            Oracle (oracle.jdbc.driver.OracleDriver)

                                            PostgreSQL (org.postgresql.Driver)

我在本地安裝的是    Oracle (oracle.jdbc.driver.OracleDriver)   選擇本地安裝的資料庫型別

在jdbc url裡面新增本地資料庫屬性:jdbc:oracle:thin:@localhost:1521:DatabaseName

其中localhost 是本地資料庫的ip地址 DatabaseName 是本地資料庫的名稱

然後在下面新增資料庫登入的使用者名稱、密碼。

點選檔案新建一張列印紙張

開啟ireport在列印紙張右側選擇image圖片,將其拖拽新增 到列印紙張上面

點選程式上面視窗屬性將列印紙張的屬性顯示在右側

點選圖片顯示圖片屬性

在屬性 image properties 下面點選Image Expression 

在彈出視窗新增  com.google.zxing.client.j2se.MatrixToImageWriter.toBufferedImage(new com.google.zxing.qrcode.QRCodeWriter().encode($F{TRANSLISTID}.toString(),com.google.zxing.BarcodeFormat.QR_CODE,100,100))

其中$F{TRANSLISTID}是資料庫中查詢出的結果,生成的二維碼就是新增的$F{TRANSLISTID}欄位

在需要生成一維碼時  將com.google.zxing.client.j2se.MatrixToImageWriter.toBufferedImage(new com.google.zxing.qrcode.QRCodeWriter().encode($F{TRANSLISTID}.toString(),com.google.zxing.BarcodeFormat.QR_CODE,100,100))修改成com.google.zxing.client.j2se.MatrixToImageWriter.toBufferedImage(new com.google.zxing.oned.Code128Writer().encode($F{TRANSLISTID}.toString(),com.google.zxing.BarcodeFormat.CODE_128,188,40))