اخواني الاعضاء
اقوم بعمل مشروع يقوم بالربط بين الكمبيوتر و الموبايل كنوع من الكلاينت و السيرفر
يقوم الموبايل بارسال رسالة للكمبيوتر الا وهو السيرفر يطلب طلب معين و بذلك يقوم الكمبيوتر بالرد عليه بارسال له النتيجة للطلب الذي طلبه الموبايل
لكي تتضح الصورة لكم
اقوم بعمل برنامج للطالب الجامعي بحيث يستطيع ان يتصل بسيرفر الجامعة لكي يستعلم عن درجاته او مواده المسجله في الفصل الدراسي
فيقوم بارسال مسج بفورمات معينه طبعا يكون عارفها السيرفر باسمه و رقمه الجامعي و نوع الطلب كاستعلام عن معدل او مواد و الى اخره
بعد ذلك يقوم السيرفر بمهمته الا وهي انه يقوم ياخد الاسم و الرقم الجامعي و الطلب ليقوم بعد ذلك بالدخول الى الديتابيس و يبحث عن الطلب الذي يريده الطالب الفلاني الذي يحمل رقم جامعي كذا و كذا و منه يقوم بارسال النتيجه للطالب الذي ارسال المسج
اني عملت الكود و لكن لم استطع ان اتعرف على الاخطاء التني بيه لانني لم اعمل انشاء للديتابيس حتى لاحظو في الكود اني حاطه دبل كوتيشن في بعض الاماكن اللي احتاج انزل له معلومات تخص الديتابيس
المشكلة يا اخواني اني لما قمت بعمل الديتابيس كريت تيبل 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);
}
}
}
}