NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

/*
Bir Veritabanına Bağlanırken,
Javanın Sağladığı SQL Sınıflarını
Kullanın
*/
import java.sql.*;

public class DB
{
// Veritabanı Bağlantısını Açan Instance
Connection c;

// Veritabanında Bir Sorgu Calistirmamizi Sağlayan
// Instance
Statement s;

// Statement Ile Calistirilmis, Geriye Veri
// Dönen Bir Sorgu (Pragma, Select) Sonucunda
// Gelen Datayı Tutan Instance
ResultSet rs;

// Bağlantı Özelliklerini Tanımlayan
// Connection String
String cS = "jdbc:sqlite://C:/Users/TuX/Desktop/test.db";

public DB() throws Exception
{
// SQLite Kutuphanesindeki Driver Sınıfını
// Belleğe Yükle
Class.forName("org.sqlite.JDBC");
// Veritabanı Bağlantısını Aç
c = DriverManager.getConnection(cS);
System.out.println("Veritabanı Açıldı");
}

// Veritabanına Kişi Eklemek İçin Method
public void addKisi(String ad) throws Exception
{
// Bağlantı Üzerinden Bir Statement Oluştur
s = c.createStatement();
// insert into kisi (ad) values ('Emre');
String sql = String.format(
"insert into kisi (ad) values ('%s');", ad);

System.out.println("SQL : "+sql);

// Açılan Statement Instance'i İle Bu Sorguyu
// Veritabanında Çalıştır
s.execute(sql);

}

public void delKisi (int id) throws Exception
{
s = c.createStatement();
s.execute("delete from kisi where id = "+id);
}

public void updKisi(int id, String ad) throws Exception
{
// update kisi set ad = 'Can' where id = 12;
String sql = String.format(
"update kisi set ad = '%s' where id = %d", ad, id);

System.out.println("SQL : "+sql);
s = c.createStatement();
s.execute(sql);
}

public ResultSet getKisiler() throws Exception
{
s = c.createStatement();
rs = s.executeQuery("select * from kisi");
return rs;
}

public ResultSet getKisi(int id) throws Exception
{
s = c.createStatement();
rs = s.executeQuery("select * from kisi where id ="+id);
return rs;
}

public static void main(String[] args) throws Exception
{
DB db = new DB();

// db.addKisi("Gokhan");
// db.delKisi(1);
// db.updKisi(3, "Ozan");

ResultSet sonuc = db.getKisiler();
// ResultSetteki Satırları Dolaş
while (sonuc.next())
{
// 1. Kolonun Değerini Int Olarak Al
int id = sonuc.getInt(1);
// Adı ad olan Kolonun Değerini String Olarak Al
String ad = sonuc.getString("ad");
System.out.println(id+" - "+ad);
}


ResultSet rs = db.getKisi(3);

while (rs.next())
{
System.out.println(rs.getString("id")+" - "+rs.getString("ad"));
}

/* ResultSet'in Yapısına Erişebildiğimiz
Nesne : ResultSetMetaData'dir
*/

rs = db.getKisiler();
ResultSetMetaData md = rs.getMetaData();
int donenKolonSayisi = md.getColumnCount();
System.out.println("MetaData --> "+donenKolonSayisi+" Kolon");
for (int i = 0; i<donenKolonSayisi; i++)
{
String kolonAdi = md.getColumnLabel(i+1);
int tip = md.getColumnType(i+1);
System.out.println("Kolon #"+i+" --> "+kolonAdi+" Tür : "+tip);

}

}
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.