DateTime bugun = DateTime.Now;
string constr = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Documents and Settings\Arastokrat.DYGOR-MOBILE\Belgelerim\Visual Studio 2008\Projects\WebSite1\DB\GelecegeMektupDB.accdb";
OleDbConnection con = new OleDbConnection(constr);
string query = "SELECT * FROM Mektuplar WHERE Tarih=@tarih;";
OleDbCommand cmd = new OleDbCommand(query, con);
cmd.Parameters.Add("@tarih", OleDbType.DBDate).Value = bugun;
OleDbDataAdapter dap = new OleDbDataAdapter(cmd);
DataSet ds = new DataSet();
dap.Fill(ds);
try
{
con.Open();
OleDbDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
if (dr.GetString(4).Equals(DateTime.Now.ToShortDateString()))
{
emailGonder(dr.GetString(1),dr.GetString(2),dr.GetString(3),dr.GetString(5));
}
}
dr.Close();
Response.Write("");
}
catch (Exception hata)
{
}
finally
{
con.Close();
}
27 Ağustos 2009 Perşembe
23 Ağustos 2009 Pazar
20 Ağustos 2009 Perşembe
HashTables
This example creates a hashtable of numbers. It uses the names of the numbers as keys:
Hashtable numbers = new Hashtable();
numbers.put("one", new Integer(1));
numbers.put("two", new Integer(2));
numbers.put("three", new Integer(3));
To retrieve a number, use the following code:
Integer n = (Integer)numbers.get("two");
if (n != null) {
System.out.println("two = " + n);
}
Hashtable numbers = new Hashtable();
numbers.put("one", new Integer(1));
numbers.put("two", new Integer(2));
numbers.put("three", new Integer(3));
To retrieve a number, use the following code:
Integer n = (Integer)numbers.get("two");
if (n != null) {
System.out.println("two = " + n);
}
18 Ağustos 2009 Salı
JAVA ile mail gonderme 2
String to = ""; // to address
String from = ""; // from address
String subject = ""; // the subject line
String message = null; // the body of the message
String mailhost = ""; // SMTP server
String user = ""; // user ID
String password = ""; // password
// password
boolean auth = true;
boolean ssl = false;
Properties props = System.getProperties();
if (mailhost != null) {
props.put("mail.smtp.host", mailhost);
}
if (auth) {
props.put("mail.smtp.auth", "true");
}
// Get a Session object
javax.mail.Session session = javax.mail.Session.getInstance(props, null);
// Construct the message
javax.mail.Message msg = new MimeMessage(session);
try {
// Set message details
msg.setFrom(new InternetAddress(from));
msg.setRecipient(javax.mail.Message.RecipientType.TO, new InternetAddress(to));
msg.setSubject(subject);
msg.setSentDate(new Date());
msg.setText(message);
// Send the thing off
SMTPTransport t = (SMTPTransport)session.getTransport(ssl ? "smtps" : "smtp");
try {
if (auth) {
t.connect(mailhost, user, password);
} else {
t.connect();
}
t.sendMessage(msg, msg.getAllRecipients());
} finally {
t.close();
}
log("Mail was sent successfully.");
} catch (Exception e) {
if (e instanceof SendFailedException) {
MessagingException sfe = (MessagingException)e;
if (sfe instanceof SMTPSendFailedException) {
SMTPSendFailedException ssfe = (SMTPSendFailedException)sfe;
log("Smtp_Send_Failed:");
}
Exception ne;
while ((ne = sfe.getNextException()) != null && ne instanceof MessagingException) {
sfe = (MessagingException)ne;
if (sfe instanceof SMTPAddressFailedException) {
SMTPAddressFailedException ssfe = (SMTPAddressFailedException)sfe;
log("Address failed:");
log(ssfe.toString());
log(" Address: " + ssfe.getAddress());
log(" Command: " + ssfe.getCommand());
log(" Return Code: " + ssfe.getReturnCode());
log(" Response: " + ssfe.getMessage());
} else if (sfe instanceof SMTPAddressSucceededException) {
log("Address succeeded:");
SMTPAddressSucceededException ssfe = (SMTPAddressSucceededException)sfe;
}
}
} else {
log("Got Exception : " + e);
}
}
String from = ""; // from address
String subject = ""; // the subject line
String message = null; // the body of the message
String mailhost = ""; // SMTP server
String user = ""; // user ID
String password = ""; // password
// password
boolean auth = true;
boolean ssl = false;
Properties props = System.getProperties();
if (mailhost != null) {
props.put("mail.smtp.host", mailhost);
}
if (auth) {
props.put("mail.smtp.auth", "true");
}
// Get a Session object
javax.mail.Session session = javax.mail.Session.getInstance(props, null);
// Construct the message
javax.mail.Message msg = new MimeMessage(session);
try {
// Set message details
msg.setFrom(new InternetAddress(from));
msg.setRecipient(javax.mail.Message.RecipientType.TO, new InternetAddress(to));
msg.setSubject(subject);
msg.setSentDate(new Date());
msg.setText(message);
// Send the thing off
SMTPTransport t = (SMTPTransport)session.getTransport(ssl ? "smtps" : "smtp");
try {
if (auth) {
t.connect(mailhost, user, password);
} else {
t.connect();
}
t.sendMessage(msg, msg.getAllRecipients());
} finally {
t.close();
}
log("Mail was sent successfully.");
} catch (Exception e) {
if (e instanceof SendFailedException) {
MessagingException sfe = (MessagingException)e;
if (sfe instanceof SMTPSendFailedException) {
SMTPSendFailedException ssfe = (SMTPSendFailedException)sfe;
log("Smtp_Send_Failed:");
}
Exception ne;
while ((ne = sfe.getNextException()) != null && ne instanceof MessagingException) {
sfe = (MessagingException)ne;
if (sfe instanceof SMTPAddressFailedException) {
SMTPAddressFailedException ssfe = (SMTPAddressFailedException)sfe;
log("Address failed:");
log(ssfe.toString());
log(" Address: " + ssfe.getAddress());
log(" Command: " + ssfe.getCommand());
log(" Return Code: " + ssfe.getReturnCode());
log(" Response: " + ssfe.getMessage());
} else if (sfe instanceof SMTPAddressSucceededException) {
log("Address succeeded:");
SMTPAddressSucceededException ssfe = (SMTPAddressSucceededException)sfe;
}
}
} else {
log("Got Exception : " + e);
}
}
16 Ağustos 2009 Pazar
JAVA ile mail gonderme
import javax.mail.*;
import javax.activation.*;
import java.util.Properties;
import java.util.Date;
public class Mesaj {
Message messages[];
int toplamMesajlar;
int yeniMesajlar;
Session session;
Store store;
Folder klasor;
private Properties props;
public Mesaj(String username,String password,String host,int port) {
try {
//Properties sinifinin örnegini(instance) olusturuyoruz.
props = new Properties();
props.put("mail.pop3.host",host);
props.put("mail.pop3.port",port);
props.setProperty("mail.pop3.socketFactory.class","javax.net.ssl.SSLSocketFactory");
props.setProperty("mail.pop3.socketFactory.fallback","false");
props.put("mail.pop3.starttls.enable","true");
//Session sinifindan, getInstance metoduyla, örnegini(instance) olusturuyoruz.
session = Session.getInstance(props,null);
//Debug true
session.setDebug(true);
//pop3 protokolunu kullanacağimizi belirtiyoruz.
store = session.getStore("pop3");
//Belirtilen host,port,username,password ile bağlantimizi gerçeklestiriyoruz
store.connect(host,port,username,password);
//INBOX klasörünü aliyoruz.
klasor = store.getFolder("INBOX");
//Klasorü READ_ONLY açiyoruz.
klasor.open(Folder.READ_ONLY);
messages = klasor.getMessages();
toplamMesajlar=klasor.getMessageCount();
yeniMesajlar = klasor.getNewMessageCount();
}
catch(MessagingException mex) {
System.err.println("Hata olustu :" +mex);
}
}
//Mesaj sinifina ait metodlar yer almaktadir.
public Date[] mesajgetDate() {
Date[] date= new Date[toplamMesajlar];
try {
for(int i=0;i date[i]=messages[i].getSentDate();
}
}
catch(MessagingException mex) {
System.err.println("Hata olustu : " +mex);
}
if(date == null) {
return null;
}
else {
return date;
}
}
public String[] mesajgetFrom() {
String[] from=new String[toplamMesajlar];
Address[] a;
try {
for(int k=0;k if ((a = messages[k].getFrom()) != null) {
for (int j = 0; j < a.length; j++) {
from[k]=a[j].toString();
}
}
}
}
catch (MessagingException mex) {
System.err.println("Hata olustu : "+mex);
}
return from;
}
public String[] mesajgetSubject() {
String[] s= new String[toplamMesajlar];
try {
for(int i=0;i
s[i]=messages[i].getSubject();
}
}
catch(MessagingException mex) {
System.err.println("Hata olustu : " +mex);
}
if(s == null) {
return null;
}
else {
return s;
}
}//mesajgetSubject();
public int toplamMesaj() {
int toplam=0;
try {
toplam = klasor.getMessageCount();
}
catch(MessagingException mex) {
System.err.println("Hata olustu: " + mex);
}
return toplam;
}
public int yeniMesaj() {
int yeni=0;
try {
yeni = klasor.getNewMessageCount();
}
catch(MessagingException mex) {
System.err.println("Hata olustu: " + mex);
}
return yeni;
}
public void closeConnection() {
try {
klasor.close(false);
store.close();
}
catch(MessagingException mex) {
System.err.println("Hata olustu: " +mex);
}
}
}
source: http://www.mutasyon.net/soruoku.asp?id=158
import javax.activation.*;
import java.util.Properties;
import java.util.Date;
public class Mesaj {
Message messages[];
int toplamMesajlar;
int yeniMesajlar;
Session session;
Store store;
Folder klasor;
private Properties props;
public Mesaj(String username,String password,String host,int port) {
try {
//Properties sinifinin örnegini(instance) olusturuyoruz.
props = new Properties();
props.put("mail.pop3.host",host);
props.put("mail.pop3.port",port);
props.setProperty("mail.pop3.socketFactory.class","javax.net.ssl.SSLSocketFactory");
props.setProperty("mail.pop3.socketFactory.fallback","false");
props.put("mail.pop3.starttls.enable","true");
//Session sinifindan, getInstance metoduyla, örnegini(instance) olusturuyoruz.
session = Session.getInstance(props,null);
//Debug true
session.setDebug(true);
//pop3 protokolunu kullanacağimizi belirtiyoruz.
store = session.getStore("pop3");
//Belirtilen host,port,username,password ile bağlantimizi gerçeklestiriyoruz
store.connect(host,port,username,password);
//INBOX klasörünü aliyoruz.
klasor = store.getFolder("INBOX");
//Klasorü READ_ONLY açiyoruz.
klasor.open(Folder.READ_ONLY);
messages = klasor.getMessages();
toplamMesajlar=klasor.getMessageCount();
yeniMesajlar = klasor.getNewMessageCount();
}
catch(MessagingException mex) {
System.err.println("Hata olustu :" +mex);
}
}
//Mesaj sinifina ait metodlar yer almaktadir.
public Date[] mesajgetDate() {
Date[] date= new Date[toplamMesajlar];
try {
for(int i=0;i
}
}
catch(MessagingException mex) {
System.err.println("Hata olustu : " +mex);
}
if(date == null) {
return null;
}
else {
return date;
}
}
public String[] mesajgetFrom() {
String[] from=new String[toplamMesajlar];
Address[] a;
try {
for(int k=0;k
for (int j = 0; j < a.length; j++) {
from[k]=a[j].toString();
}
}
}
}
catch (MessagingException mex) {
System.err.println("Hata olustu : "+mex);
}
return from;
}
public String[] mesajgetSubject() {
String[] s= new String[toplamMesajlar];
try {
for(int i=0;i
s[i]=messages[i].getSubject();
}
}
catch(MessagingException mex) {
System.err.println("Hata olustu : " +mex);
}
if(s == null) {
return null;
}
else {
return s;
}
}//mesajgetSubject();
public int toplamMesaj() {
int toplam=0;
try {
toplam = klasor.getMessageCount();
}
catch(MessagingException mex) {
System.err.println("Hata olustu: " + mex);
}
return toplam;
}
public int yeniMesaj() {
int yeni=0;
try {
yeni = klasor.getNewMessageCount();
}
catch(MessagingException mex) {
System.err.println("Hata olustu: " + mex);
}
return yeni;
}
public void closeConnection() {
try {
klasor.close(false);
store.close();
}
catch(MessagingException mex) {
System.err.println("Hata olustu: " +mex);
}
}
}
source: http://www.mutasyon.net/soruoku.asp?id=158
1 Ağustos 2009 Cumartesi
Excel'den veri okuma
1. Önce http://sourceforge.net/projects/jexcelapi/files/ adresinden jxl.jar dosyasını indir.
2.Projenin altında Libraries -> right click -> Add jar file ile jxl.jar'ı projeye ekliyoruz.
3. kod şu şekilde:
import java.io.*;
import java.io.File;
import jxl.*;
import java.util.Date;
import javax.swing.JOptionPane;
/**
*
* @author Arastokrat
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main (String[] args) {
// TODO code application logic here
try{
Workbook kitap=Workbook.getWorkbook(new File("C:\\Documents and Settings\\Arastokrat.DYGOR-MOBILE\\Belgelerim\\JAVA\\liste.xls"));
Sheet sayfa=kitap.getSheet(0);
Cell hucre0=sayfa.getCell(0, 0); //(sutun, satır)
String data=hucre0.getContents();
System.out.println(data);
kitap.close();
//JOptionPane.showInputDialog(data);
}
catch(Exception ex){
ex.printStackTrace();
}
}
}
NOT: Excel 2003 için geçerli. 2007 de çalışöıyor.
Sutunları x, satırları y olarak alıyor.
2.Projenin altında Libraries -> right click -> Add jar file ile jxl.jar'ı projeye ekliyoruz.
3. kod şu şekilde:
import java.io.*;
import java.io.File;
import jxl.*;
import java.util.Date;
import javax.swing.JOptionPane;
/**
*
* @author Arastokrat
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main (String[] args) {
// TODO code application logic here
try{
Workbook kitap=Workbook.getWorkbook(new File("C:\\Documents and Settings\\Arastokrat.DYGOR-MOBILE\\Belgelerim\\JAVA\\liste.xls"));
Sheet sayfa=kitap.getSheet(0);
Cell hucre0=sayfa.getCell(0, 0); //(sutun, satır)
String data=hucre0.getContents();
System.out.println(data);
kitap.close();
//JOptionPane.showInputDialog(data);
}
catch(Exception ex){
ex.printStackTrace();
}
}
}
NOT: Excel 2003 için geçerli. 2007 de çalışöıyor.
Sutunları x, satırları y olarak alıyor.
Kaydol:
Kayıtlar (Atom)