import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
public class veritabani extends JFrame implements ActionListener {
DefaultListModel<String> dlm;
public veritabani()
{
this.setTitle("Veritabanina Giris:Sqlite");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(150,300);
this.setLayout(new FlowLayout());
JPanel jpn_main= new JPanel();
jpn_main.setPreferredSize(new Dimension(140, 290));
dlm = new DefaultListModel<String>();
JList<String> jl = new JList<String>(dlm);
JScrollPane jscp = new JScrollPane(jl);
jscp.setPreferredSize(new Dimension(130, 250));
JButton jbtn = new JButton("Göster");
jbtn.setPreferredSize(new Dimension(130, 30));
jbtn.addActionListener(this);
jpn_main.add(jscp);
jpn_main.add(jbtn);
this.add(jpn_main);
this.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent arg0) {
Connection conn = baglan();
if(conn!=null)
{
dlm.clear();
try{
String sql = "select isim from kisiler;";
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery(sql);
while(rs.next())
{
dlm.addElement(rs.getString("isim"));
}
}catch(Exception ex)
{
JOptionPane.showMessageDialog(this, ex.getMessage());
}
}
}
public Connection baglan()
{
Connection conn=null;
try{
Class.forName("org.sqlite.JDBC");
conn=DriverManager.getConnection("jdbc:sqlite:orgun1hafta6.db");
}catch(Exception ex)
{
JOptionPane.showMessageDialog(this, "Baglanti Hatasi!");
}
return conn;
}
/**
* @param args
*/
public static void main(String[] args) {
new veritabani();
}
}
NTP2 (Bahar-2016) Hafta-6/1
sqlite-jdbc