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

ببساطة كيف يتم التعامل بين Java & SQL

مغلقرائج
بدأه رامي العيساوي في 6 يونيو 2003 · 57 رد · 3,874 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

ببساطة كيف يتم التعامل بين Java & SQL لانني لست ذو معرفة في هذا المجال و لكن ظروف العمل الحالية تتوجب ان اتعامل مع قوعد SQL و قد كنت مسبقا اكتب و اقرا جميع المعلومات التي احتاجها في ملف عادي و كانت هذه الطريقة تحل لي كثير من المشاكل و لكن مع كثرة الملفات و تعقد الامور اصبحت بحاجة الى قواعد SQL و لكن احتاج الى ان ترشدوني الى بداية الطريق و لا تاكلوا همي بعدين...

انا احتاج ببساطة ان اعرف مما تتالف قواعد SQL اي من جداول و مثل هذه الاشياء الاخرى و كيف يتم التعامل معها عن طريق الجافا بابسط شكل ممكن و ياريت تدعموني بمثال...

==========:cool:

اخوكم Java Man

==========:cool:

Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know why

#2

السلام عليكم

يمكنك مراجعة موضوع كود لعمل phonebook للاخ علاءالدين

ففيه يتعامل مع sql وقواعد البيانات اكسيس

اذا لم تجة قلى وانا اضع نفس الكود بموضوع جديد

#3

لقد وجدته اخي العزيز و لكن هو بعيد عن ما اهدف اليه فانا كل رغبتي تكمن في صفحة JSP و ليس تطبيق عادي و اريد من هذه الصفحة ان تكتب في جدول الزوار حقول حول رقمه المتسلسل و عنوان IP و نوع المتصفح هذه المعلومات اعرف استخرجها و لكن كيف تخزينها و القراءة منها باستخدام SQL

و شكرا

Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know why

#4

it depends on what database are you using and how you connect to it

If you are using ODBC datasources then your life is easy because Java have the drivers for ODBC

If you want to make the conneciton to MSSQL, Oracle or even Access Database using ODBC

go to :Control Panel --- Administrative tools --- ODBC data sources

there, you will choose add and choose your database driver

for the simplest case you will use MS Access or maybe MS SQL2000

you will choose your file *.mdb or whatever and give a name to the datasource

in your program you will do the following

 try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e){
System.err.println("Failed to load driver");
}

This will load the ODBC drivers , which is supported by Java

there's another case where you will make the connection to a server "the database is not locally stored" then you will need to use server specific drivers .. but this is not the case with you

To create the Connection

try{
conn = DriverManager.getConnection("jdbc : odbc : datasourcename");
}
catch(SQLException e){
System.err.println("Unable to connect");
}

where conn is of Type Connection

now, to insert something in the table you will do this

Statemebt stms = conn.createStatement();

stmt.excuteUpdate(yourInsertQuery);

and to retrieve data you will use

ResultSet res = stmt.executeQuery(yourSelectStmt);

You will then use the res.next() to traverse through the ROWS in your Result set

and res.getInt(x) , re.getString(x) etc to get data in the columns where x is the column index OR the column name

sorry to write english

#5

انا لدي مساحة JSP مع قاعدتي SQL و اديرهما عن طريق برنامج phpMyadmin و هل يوجد انواع لقواعد SQL و سوف احاول بالطريقة التي اعطيتني ايها و شكرا لك

Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know why

#6

اخي انا اريد التعامل فقط مع قاعدة SQL التي اتتني مع المساحة و لااريد قاعدة بيانات الاكسس ابدا .

و لدي كلمة سر واسم المستخدم و اسم قاعدة البيانات و المضيف هو "LOCAL HOST" لان صفحة jsp و قاعدة SQL على نفس المخدم

فكيف استطيع ادخال هذه البيانات في الجافا و التصال بقاعدة البيانات خاصتي و الكتابة فيها و القراءة منها بشكل مبسط

و شكرا لك جزيل الشكر

Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know why

#7

ماهي قاعدة البيانات لديك

اللهم انا نسألك علما نافعا ونعوذ بك من حماقة الجهلاء
#9

MySQL 3.23.54 running on localhost

هذا ما يظهر لي في لوحة التحكم

Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know why

#10

الطريقه انا شرحتها بالقسم لكن للاوراكل و الاكسس

اعتقد ان الـ MySQL تحتاج الى Driver ترفقه مع الملفات

#11

see the link

http://www.arabteam2000.com/vb/showthread....&threadid=29092

اللهم انا نسألك علما نافعا ونعوذ بك من حماقة الجهلاء
#12

اخ جافا مان لحل مشكلتك يلزمك عدة خطوات متالية

1. class للربط مع database والتعامل معها مثل

select-statment, insert-statment, update-statment, delete-statment

هذه ال class قد كتبتها في موقع اخر

2. لكل jsp تحتاج الى Beans معين

3 في Beans استخدم ال Methode getxxx حيث getxxx تحضر البيانات من Database

4. استدعي ال Bean مع الMethode getxxx في JSP

5. على سبيل المثال تريد عرض اسماء الموضفين في JSP

اتبع مايلي

انشء Bean تحت اسم PersonBean

في PersonBean انشئ Instance من Class من نوع RunSql

Methode gatAll هي لارجاع كل بيانات كل الأشخاص

public Vector getAll()
{
Vector temp=null;
try
{ 
 RunSql rsql=new RunSql();
  String str="select * from Personal order by personalnr";
  temp=rsql.runSelect(str); 
}  
catch(Exception e)
{
System.out.println(e.toString());
}
try
{
rsql.closedatabase();
}
catch(Exception ex)
{
System.out.println(ex.toString());
}
return temp;
}

في JSP استدعي ما يلي:

استدعي ال Method getAll في JSP

<%! Vector personsData=pbean.getAll();
%>

اطبع محتوى ال Vector على شكل جدول في JSP

اللهم انا نسألك علما نافعا ونعوذ بك من حماقة الجهلاء
#13

هل يوجد Bean جاهزة و خالصة احسن ما اكتب و اتعذب كل مرة... سوف ابحث في الانترنت عن هذا الشئ ارجو ان تساعدني ايضا بمعرفتك..

و شكرا

Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know why

#14

المثال السابق لعرض بيانات لجدول ما في Database في هذه الحالة اعتقد انه يجب على المبرمج كتابة ال Bean بنفسه حسب مايحتاجه

اللهم انا نسألك علما نافعا ونعوذ بك من حماقة الجهلاء
#15

لقد بحثت في الانترنت عن هذا الموضوع و قد و جدت الكثير سوف ادرسه و ارتبه و اعرض الخلاصة هنا

Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know why

#17

تكرم اخي انا الآن قد اقتربت من الحل جدا فقد و سوف اكتبه بشكل درس و انشره هنا

Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know why

#18

على كل حال هذا ما توصلت اليه لحد الآن:

import java.sql.*;



   public class Connect

   {

       public static void main (String[] args)

       {

           Connection conn = null;



           try

           {

               String userName = "testuser";

               String password = "testpass";

               String url = "jdbc:mysql://localhost/test";

               Class.forName ("com.mysql.jdbc.Driver").newInstance ();

               conn = DriverManager.getConnection (url, userName, password);

               System.out.println ("Database connection established");

           }

           catch (Exception e)

           {

               System.err.println ("Cannot connect to database server");

           }

           finally

           {

               if (conn != null)

               {

                   try

                   {

                       conn.close ();

                       System.out.println ("Database connection terminated");

                   }

                   catch (Exception e) { /* ignore close errors */ }

               }

           }

       }

   }

و لكنني اريد استبدال local host باسم موقع او هوست على الانترنت فكيف ذلك

Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know why

#20

شكرا اخي انا الآن احاول و لكن الكود الذي رايته فوق لا يعمل لماذا لا اعرف؟

Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know why

#21

اضف الى البرنامج قراءة بيانات واطبعها على الشاشة

فهل عمل الconnect ام لا

اللهم انا نسألك علما نافعا ونعوذ بك من حماقة الجهلاء
#22

كلا اخي هو لم يعمل الconnect من الاصل حتى ابدا بقراءة البيانات

Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know why

#23

ما الرسالة التي طبعها

اللهم انا نسألك علما نافعا ونعوذ بك من حماقة الجهلاء
#24

Cannot connect to database server

سوف احاول حذفها و اشوف الـ Exception شو رح يكتب ربما يحدد لي اكثر الخطا

Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know why

#25

The server to which you want to connect must open some port i am not sure.... another thing that you might need to configure your program to use a proxy server.... i remember i had a hard time to do that.. but hey i am NOT sure

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

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