Aşağıdaki linklerden kütüphaneyi indiriyorsunuz.
Link1= http://dfiles.eu/files/78m582ipy
veya
Link2= http://www.2shared.com/file/xuj8yEVL/org.html
Kütüphaneleri indirdikten sonra Flex projenizin src dosyasına altına kopyalayın.
Aşağıdaki kod parçasını Script olarak çalıştırabilirsiniz.
protected function ozgecmisCikti(event:MouseEvent):void
{
var myPDFEncoder:PDF = new PDF (Orientation.LANDSCAPE, Unit.MM);
myPDFEncoder.setDisplayMode(Display.FULL_PAGE);
myPDFEncoder.addPage();
myPDFEncoder.addImage(personelBilgiPanel,null,0,0,myPDFEncoder.getMargins().w idth,myPDFEncoder.getMargins().height);
myPDFEncoder.addPage();
myPDFEncoder.addImage(PANELID,null,0,0,myPDFEncoder.getMargins().width,myPDFEncoder.getMargins().height);
var bytes:ByteArray = myPDFEncoder.save(Method.LOCAL);
var fx:FileReference = new FileReference();
fx.save(bytes,"test.pdf");
}
Yukarıda PANELID yazan yere herhangi bir panelinize ait idsini yazdığınızda panelin tamamı pdf'e aktrılır.
Panel herhangi bir flex tag'i olabilir. Örneğin : <s:Panel/> , <s:NavigatorContent/>
Metodu herhangi bir butona veya başka birşeye click event olarak eklerseniz "test.pdf" çıktısını üretmiş olacaktır.
17 Nisan 2013 Çarşamba
1 Mart 2013 Cuma
Java String değişken ismi ile değerini elde etmek
Bir Java sınıfında kendi içerisinde tanımlanmış
String değişkenlerin ismi ile değerini elde eden kod parçası
import java.lang.reflect.Field;
public class test {
private static test instance = null;
public static test getInstance(){
if(instance==null){
instance=new test();
}
return instance;
}
public static String getData1 = "MERHABA DÜNYA";
public static void main(String[] args) throws Exception {
test t=test.getInstance();
System.out.println(t.getSqlStringByName("getData1"));
}
public String getSqlStringByName(String param) throws Exception{
String value="";
for (Field f : this.getClass().getFields()) {
if(param.equals(f.getName())){
value=f.get(this).toString();
break;
}
}
return value;
}
}
String değişkenlerin ismi ile değerini elde eden kod parçası
import java.lang.reflect.Field;
public class test {
private static test instance = null;
public static test getInstance(){
if(instance==null){
instance=new test();
}
return instance;
}
public static String getData1 = "MERHABA DÜNYA";
public static void main(String[] args) throws Exception {
test t=test.getInstance();
System.out.println(t.getSqlStringByName("getData1"));
}
public String getSqlStringByName(String param) throws Exception{
String value="";
for (Field f : this.getClass().getFields()) {
if(param.equals(f.getName())){
value=f.get(this).toString();
break;
}
}
return value;
}
}
27 Şubat 2013 Çarşamba
Oracle sql with kullanımı
Oracle sql with kullanımı
With kullanımı Prosedürlerdeki cursor gibi düşünebiliriz.
Bir örnek üzerinde gerçekleştirelim.
Öğrenci tablosu (OGRENCI)
OGRENCI_ID OGRENCI_ADI
1
Ahmet
2
Ayşe
3
Hasan
Ders tablosu (DERS)
DERS_ID DERS_ADI
1
Matematik
2
Tarih
3
Türkçe
Bir dersi alan Öğrenci tablosu (OGRENC_DERS)
DERS_ID OGRENCI_ID
1 1
1 2
1 3
2 1
2 3
3 2
3 3
Ders alan öğrencilerin sql’ini yazalım.
Select od.OGRENCI_ID,d.DERS_ADI,
d. DERS_ID
From OGRENCI_DERS od
,DERS d
Where od.DERS_ID=d.DERS_ID
Öğrenci numaralarıyla ders isimlerini listeledik. Bizim
buradaki isteğimiz bir öğrenciye ait
ders bilgilerini alt alta getirmek yerine yan yana getirmeyi sağlamak
olacaktır. Yukarıdaki sql cümleciğini with aralığına alacağız.
Son sql hali
With tablo
as
(
Select od.OGRENCI_ID,d.DERS_ADI,d. DERS_ID
From OGRENCI_DERS od ,DERS d
Where od.DERS_ID=d.DERS_ID
)
Select o.OGRENCI_ADI,
(select t.DERS_ADI
from tablo t where tablo t. OGRENCI_ID=o. OGRENCI_ID and o.DERS_ID =1) as DERS1,
(select t.DERS_ADI
from tablo t where tablo t. OGRENCI_ID=o. OGRENCI_ID and o.DERS_ID =2) as DERS2,
(select t.DERS_ADI
from tablo t where tablo t. OGRENCI_ID=o. OGRENCI_ID and o.DERS_ID =3) as DERS3,
From OGRENCI
o
Sql Sonucu
OGRENCI_ADI DERS1 DERS2 DERS3
AHMET MATEMATİK TARİH NULL
AYŞE MATEMATİK NULL TÜRKÇE
HASAN MATEMATİK TARİH TÜRKÇE
24 Şubat 2013 Pazar
Java Adaptör Tasarım Deseni Örneği
Date(tarih) değerini göndererek bize formatını getiren Adapter tasarım deseni örneğini yapacağız.
Bu örnekte Date değerinin Web Servis,Veritabanı vb. yoluyla gelen bir değer olarak düşünebiliriz.
Gelen date değerinin formatı elde edebiliriz.
Nesnelerimiz SimpleDateFormat nesnelerinin aldığı constructor parametresiyle oluşturduk.
Örneğin
-1.nesne dd.MM.yyyy parametreli
-2.nesne dd/MM/yyyy parametreli
-3.nesne dd:MM:yyyy parametreli
import java.util.Date;
import java.text.SimpleDateFormat;
class DateFormatAdapter{
private SimpleDateFormat dt=null;
private String format1="dd.MM.yyyy";
private String format2="dd/MM/yyyy";
private String format3="dd:MM:yyyy";
public String getFormat(Date d){
try {
dt=new SimpleDateFormat(format1);
dt.format(d);
return format1;
} catch (Exception e) {
try {
dt=new SimpleDateFormat(format2);
dt.format(d);
return format2;
} catch (Exception e2) {
try {
dt=new SimpleDateFormat(format3);
dt.format(d);
return format3;
} catch (Exception e3) {
return "";
}
}
}
}
}
class DateFormatAdapter{
private SimpleDateFormat dt=null;
private String format1="dd.MM.yyyy";
private String format2="dd/MM/yyyy";
private String format3="dd:MM:yyyy";
public String getFormat(Date d){
try {
dt=new SimpleDateFormat(format1);
dt.format(d);
return format1;
} catch (Exception e) {
try {
dt=new SimpleDateFormat(format2);
dt.format(d);
return format2;
} catch (Exception e2) {
try {
dt=new SimpleDateFormat(format3);
dt.format(d);
return format3;
} catch (Exception e3) {
return "";
}
}
}
}
}
Adapter nesnemizin testi aşağıdaki gibidir.
import java.util.Date;
import java.text.SimpleDateFormat;
public class TestClass {
public static void main(String[] args) throws Exception{
DateFormatAdapter adapter=new DateFormatAdapter();
Date d=new Date(); //Tarihi elle tanımladığımızda varsayılan formatı ekranı yazdıracaktır.
//Format dd.MM.yyyy olacaktır.
System.out.println(adapter.getFormat(d));
}
}
21 Şubat 2013 Perşembe
Oracle tablo döndüren fonksiyon
Aşağıdaki adımları sırayla uygulayacağız.
1.Oracle Type oluşturma
3.Fonksiyon oluşturma
4.Oluşturulan tabloyu sql içerisinde kullanmak
sql sonucu
1 Ahmet
2 Ayşe
3 Hasan
Fonksiyonun parametreli hali.Fonksiyona kaydın id’si parametre ile verilerek kaydın getirilmesi
1.Oracle Type oluşturma
create or replace type ornekType as object (
i number,
n varchar2(30)
);
2.Oracle Nested Type oluşturmai number,
n varchar2(30)
);
create or replace type Ornek_nested_table as table of ornekType;
create or replace function ornekFonksiyon return Ornek_nested_table as
temp_tab Ornek_nested_table;
begin
temp_tab:= Ornek_nested_table();
temp_tab.extend;
temp_tab (temp_tab.count) := ornekType(1, 'Ahmet');
temp_tab.extend;
temp_tab (temp_tab.count) := ornekType(2, 'Ayşe');
temp_tab.extend;
temp_tab (temp_tab.count) := ornekType(3, 'Hasan');
return temp_tab;
end ornekFonksiyon;
select * from table(ornekFonksiyon);
1 Ahmet
2 Ayşe
3 Hasan
Fonksiyonun parametreli hali.Fonksiyona kaydın id’si parametre ile verilerek kaydın getirilmesi
create or replace function ornekFonksiyon2(
personel_id in number
)
return Ornek_nested_table as
temp_tab Ornek_nested_table;
begin
select
cast(
multiset(
select
id, name
from
personel
where id= personel_id)
into
temp_tab
from
dual;
return temp_tab;
end ornekFonksiyon2;
Sql'i bu şekilde olur.Sonucu "1 Ahmet"
select * from table(ornekFonksiyon2(1));15 Şubat 2013 Cuma
Veritabanından Blob veya Clob Veri Türlerini Java ile okutmak
Veritabanınlarıda veri tipi Blob veya Clob olan
datayı aşağıdaki metodlara parametre olarak
gönderip Metin olarak elde edebiliriz.
Clob için
----------------------------------------------------------------
public String readClob(Clob data) throws Exception
{
StringBuilder sb = new StringBuilder();
try {
Reader reader = data.getCharacterStream();
BufferedReader br = new BufferedReader(reader);
String line;
while(null != (line = br.readLine())) {
sb.append(line);
}
br.close();
} catch (SQLException e) {
// handle this exception
} catch (IOException e) {
// handle this exception
}
return sb.toString();
}
public String readBlob(Object clob1) throws Exception
{
Blob clob=(Blob) clob1;
InputStream is = clob.getBinaryStream();
StringBuffer sb = new StringBuffer();
int readedBytes;
int bufferSize = 4096;
do {
byte[] bytes = new byte[bufferSize];
readedBytes = is.read(bytes);
if (readedBytes > 0) {
String readed = new String(bytes, 0, readedBytes, "UTF-16");
sb.append(readed);
}
} while (readedBytes == bufferSize);
is.close();
return sb.toString();
}
Blob için
----------------------------------------------------------------
public String readBlob(Object clob1) throws Exception
{
Blob clob=(Blob) clob1;
InputStream is = clob.getBinaryStream();
StringBuffer sb = new StringBuffer();
int readedBytes;
int bufferSize = 4096;
do {
byte[] bytes = new byte[bufferSize];
readedBytes = is.read(bytes);
if (readedBytes > 0) {
String readed = new String(bytes, 0, readedBytes, "UTF-16");
sb.append(readed);
}
} while (readedBytes == bufferSize);
is.close();
return sb.toString();
}
13 Şubat 2013 Çarşamba
Oracle sql sorgusunu xml e çevirmek
Veritabanı tablolarımızda bazen hiyerarşik veriye ihtiyaç duyarız.
Aşağıda daha önce verdiğim bir örnek üzerinde gidelim.
----------------------------------
Örnek Tablo=Personel
tablo sütunları sırasıyla
Personel_id,Personel_adi,Bagli_Personel_id
Veriler
-------------------------------------------------------------
0 'Üst personel' -1
1 'Murat' 0
2 'Ahmet' 1
3 'Mehmet' 1
4 'Duygu' 1
5 'Ayşe' 4
6 'Ali' 4
Bu tablodan da gördüğümüz gibi Murat personeline bağlı 3 personel var.Bu 3 personelden Duygu ya bağlı 2 personel var.Bu bilgileri hiyerarşik olarak getirmek
istiyorsanız aşağıdaki oracle sql yazıyoruz.
select Personel_adi
from personel start with personel_id=1
connect by prior personel_id=Bagli_Personel_id
Sqlden gelen sonucu xml le çevirmek istiyorsak aşağıdaki gibi yazabilirsiniz.
select xmlelement("PERSONEL_LISTESI",
(select dbms_xmlgen.getxmltype(dbms_xmlgen.newcontextFromHierarchy('
select LEVEL,xmlelement("Personel_adi",xmlelement("Personel_adi",Personel_adi ))
from personel start with personel_id=1
connect by prior personel_id=Bagli_Personel_id
order siblings by Personel_adi
'))
from dual)
) xmldoc
from dual
Kaydol:
Kayıtlar (Atom)