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

برمجة سيرفر يقوم بدخول الديتابيس

بدأه زينب فيصل في 21 فبراير 2008 · 2 رد · 677 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

اخواني الاعضاء

اقوم بعمل مشروع يقوم بالربط بين الكمبيوتر و الموبايل كنوع من الكلاينت و السيرفر

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

لكي تتضح الصورة لكم

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

فيقوم بارسال مسج بفورمات معينه طبعا يكون عارفها السيرفر باسمه و رقمه الجامعي و نوع الطلب كاستعلام عن معدل او مواد و الى اخره

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

اني عملت الكود و لكن لم استطع ان اتعرف على الاخطاء التني بيه لانني لم اعمل انشاء للديتابيس حتى لاحظو في الكود اني حاطه دبل كوتيشن في بعض الاماكن اللي احتاج انزل له معلومات تخص الديتابيس

المشكلة يا اخواني اني لما قمت بعمل الديتابيس كريت تيبل making setting first

i download mysql database 5.0.51a

and when i try to create database instance i opend the mysql commend line client

when i pressed the password

it appear

mysql>

so i wrote create database StudentTable

when i press enter it appear -> istead of appearing "query ok" as what in tutorial

i tried to solve that problem but i cant i spend one week try sloving but i couldnt and i cant continue working until this finding solution

please i will post the code here and if there is any problem occure in it please tell me and we will try to solve it togather

i used

netbeans 5.5.1

mysql database 5.0.51a

jdbc driver for sql 5.0.8

import java.net.*;

import java.io.*;

import java.util.ArrayList;

import java.sql.*;

public class PcServer extends Thread {

// declare unbound server socket

private ServerSocket ServS =null ;

//declare unconnected client socket

private Socket ClientConnection = null;

// input stream from client

private ObjectInputStream IS;

//output stream to client

private ObjectOutputStream OS;

//CONSTRUCTOR

public PcServer (Socket ClientSocket){

ClientConnection = ClientSocket;

}

// set up run server

public void runServer(){

try //creat server socket

{ ServS = new ServerSocket (3131);//3131 is the port number

}

catch (IOException e) {

System.err.println("Could not listen on port:3131");

System.exit(-1);

}

boolean listening = true;

while (listening)

{ try

{ ClientConnection = PcServer.accept();//allow server to accept connection from client

//open input stream from the socket connection to read the data from the client

IS=new ObjectInputStream(ClientConnection.getInputStream());

//open data out stream from the socket connection to write data to the client

OS=new ObjectOutputStream (ClientConnection.getOutputStream());

//start the process(sending and recieving data) from/to client

startExchange();

}

catch (IOException Ex){

Ex.printStackTrace();

}

try // terminate all connection and close stream gate

{ OS.close();

IS.close();

ClientConnection.close();}

catch (IOException ex)

{ ex.printStackTrace();}

}

}

//start the process of the program

public void starExchange(){

String msg =(String)IS.readObject();//read msg coming from client

//EON=End Of Name

int EON = msg.indexOf('-');

//message getting from client = name-id-request

// extract the name from the msg

String name = msg.substring(0, EON);

//extract id from the msg

long ID = Long.ParseLong(msg.substring(EON+1, EON+9));

//extract request from the msg

String Request = msg.substring(EON+10, msg.length());

//JDBC driver name and database URL

Static final String JDBC-DRIVER ="";

Static final String DATABASE-URL="";

//manage database connection

Connection DBconnection = null;

Statement DBstatement = null; // query statement

//connect to the student database and query database

try {

// load database driver class

class.forName (JDBC-DRIVER);

//establish connection to database

DBconnection = DriveManagaer.getConnection (DATABASE-URL,"","");

//create statement for quering database

DBstatement = DBconnection.createStatement();

request(Request,name,ID);

}

catch (SQLException sqlException){

sqlException.printStackTrace();

}

finally // close DBstatement and DBconnction

{

try

{ DBstatement.close();

DBconnection.close();

}

catch (Exception exception)

{ exception.printStackTrace();

}

}

}

public void request ( String R,String N,long id)

{

//query database

ResultSet resultset = DBstatement.executeQuery("SELECT"+R+"FROM Student-Table WHERE ID="

+id+"AND NAME="+N);//select the result according to the name and id of student

// return the result according to the request

OS.writeObject("NAME:"+N+"-ID:"+id+"-"+R+"is"+resultset+"/n Do you need to get othe information?/n" +

"send (Y/N) with your request if Y");//SEND RESULT OF STUDENT REQUEST

String newR=(String) IS.readObject();//READ THE STUDENT RESPOSE

//CHECKING IF CLIENT WANTS TO GET OTHE INFO.

if (newR.charAt(0)=='y'||newR.charAt(0)=='Y')

{ // extract client request

String newReq=newR.substring(2,newR.length());

//recursive function...check other request

request(newReq,N,id);

}

}

}

}

#2

لم ادقق كثيرا...

و لكن لدي سؤال هل برمجة برنامج ME على الموبايل لكي يتصل

ام انك تريد من متصفح الموبايل ان يدخل على صفحة الـ jsp و يعطيها البرمترات؟؟

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

#3

سلام اخي رامي

والله انا ما فهمت عدل على سؤالك

بس انا راح ادز رسالة من الهاتف بعد ما يصير accept connection between server and mobile"client " with specific message format as appearing in the code "name-id-request" did you see it

بعدين

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

يعني انا الفكرة اللي في راسي اني اعمل سوكت كونكشن ما بينهم و يتبادلون بعد ذلك الرسائل

مشكور يا اخر رامي على المشاركة و صراحه بأسالتك فتحت عيوني على اشياء يمكن ناسيتها و بعد انا جديدة بس مو كلش يعني نص و نص جديدة في لغة الجافا و اعتمادي كله يكون بالبحث و القراءة من النت حيث ان بلدي تفتقر من مبرمجي الجافا حيث انها ليست لغة السوق في وقتها الحاضر

فارجو لو تكرمتم بنصيحة و ليست بمعنى المساعده و انمت توجيه و انا اعمل بشكل دؤوب على البرنامج

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

عدد الزوار حالياً

المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…