الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

نبي تعاون الجميع

مغلق
بدأه المع في 27 مايو 2002 · 1 رد · 724 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

يا جماعة نبي نتعاون و نشوف طريقة ربط قاعدة البيانات عن طريق

الجافا ..... وش رايكم؟؟؟:cool:

#2

Here are the steps to access database in Java:

-First import javax.sql packages becuase all the classes you need are there

-Load the JDBC Driver class at run time.This can be sun.jdbc.odbc.JdbcOdbcDriver if you are accessing a database registered in the ODBC.

-create the url string that represent your ODBC data source name.For example if your ODBC data source name is Products the url will be:

jdbc:odbc:Products

-Create the Connection object using the JDBC driver manager by passing the url as an argument

-Create the Statement object which allows you to query the database

-Create The ResultSet which represents your database rows

-Use a while loop to go through the resultset and get the field values

-Cloase Connection and statement

-Catch any SQLException

String url = "jdbc:odbc:Products";

Connection con;
Statement stm;
ResultSet rs;


        try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        } catch(java.lang.ClassNotFoundException e) {
            System.err.print("ClassNotFoundException: ");
            System.err.println(e.getMessage());
        }

        try {
con = DriverManager.getConnection(url,"username","password");

            stm = con.createStatement();


rs = stm.executeQuery("select*from Orders");

while(rs.Next()) {

System.out.Println(rs.getString("ProductNam"););
System.out.println(rs.getFloat("Total"));

stm.close();
con.close();

}
catch(SQLException e) {

System.out.println(e.toString());

}

As I said you need to import the javax.sql package on the top of the class.

Tahiyati

Madani

هذا الموضوع مغلق.

مواضيع مشابهة