Yusuf Şahin
Blog myBlog= new Blog("Daima Öğrenci");


JDBC ile MySQL bağlantısı

Nisan 27, 2008 23:37 by Yusuf Sahin
package net.yusufsahin.pk1;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;


public class MainProgram {
       
public static void main(String[] args) {

                   try {
                      
Class.forName("com.mysql.jdbc.Driver");
                      
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/sakila", "yourUserName", "yourPassword");
                      
PreparedStatement ps = con.prepareStatement("select customer_id,first_name,last_name from customer");
                       
ResultSet rs = ps.executeQuery();

                                    while(rs.next()){

                                   System.out.println(rs.getInt("customer_id")
                                  
+"-"+rs.getString("first_name")
                                   
+" "+rs.getString("last_name"));
                                   
}

                   } catch (Exception {
                             
e.printStackTrace();
                            
}
            
}
}

Aşağıdaki gibi bir çıktı elde etmelisiniz.

Related posts

Yorum ekle


(Gravatar simgesini gösterecek)  

  Country flag




Live preview

Kasım 22. 2008 05:03

Gravatar