j'ai créer un pgme(client/serveur) le serveur
j'ai entrain de le programme de bdd en mon code mais c'est trés defficile de faire aide moi
mon code java et
le serveur:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98 import java.io.*; // for input output import java.lang.*; // for Threads import java.net.*; // sockets public class serverChat { public static void main(String args[]) throws IOException { /*******Declarations**********/ // Ports and Hosts int port = 3000; // port to the PDA client // Sockets ServerSocket serverSocket = null; // ServerSocket listening to the Client Socket clientSocket = null; // Socket with Client // Inout/Output for PDA Client BufferedReader isClient = null; // BufferedReader from PDA Client PrintWriter osClient = null; // OutputStream to PDA Client // Strings String msg_String = null; int msg_hash = 0; int i = 0; int Clientconnected = 0; // Connection marker /********End declarations*********/ /****************Server Socket Creation**********/ System.out.print( "\nCreation of the ServerSocket\nlistening to port 3000\nfor client."); try { System.out.print("."); serverSocket = new ServerSocket(port); // Creation of the server Socket listening on port 3000 System.out.print("..started.\n\n"); } catch (IOException e) { System.out.print( "...failed.\nProblem in the creation of the ServerSocket : " + e); System.exit(1); } try { clientSocket = serverSocket.accept(); // now we are connected Clientconnected = 1; // we just mark here that we are connected } catch (IOException e) { System.out.println( "Unable to deal with BufferedReader and PrintWriter for the clientSocket : " + e); System.exit(1); } /***************End of creation of Sockets**********/ try { isClient = new BufferedReader(new InputStreamReader(clientSocket. getInputStream())); // InputStream from Client osClient = new PrintWriter(clientSocket.getOutputStream()); // prepare an OutputStream for the Client } catch (IOException e) { System.out.println("Cant't deal with the streams : " + e); } while (true) { try { msg_String = isClient.readLine(); // taking the String from it System.out.println("String from the client : " + msg_String); } catch (IOException e) { System.out.println("Couldn't get I/O for the connection to: "); System.exit(1); } if (msg_String.trim().equals("/bye")) { Clientconnected = 0; // the server is now disconnected clientSocket.close(); serverSocket.close(); System.exit(0); } if (Clientconnected == 1) { // if the client is connected try { System.out.print("\nComputing..."); msg_hash = msg_String.hashCode(); System.out.print("done"); osClient.println(msg_hash); osClient.flush(); // put it onto the network System.out.print("...and sent.\n"); } //try catch (Exception e) { System.out.println(e); System.exit(1); } // catch } // if Clientconnected } // while // System.exit(0); } // void main } // PDAServer class
et le code pour integri la bdd :
comment placer le dernier code dande le premier j'ai essai mais c'est trés defficile
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 import java.sql.*; public class acces { public static void main(String[] args) { try { Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver"); Connection c = DriverManager.getConnection( "jdbc:odbc:morph"); Statement s = c.createStatement(); s.executeUpdate( " INSERT INTO sac_mot (N°,mot,frequence) VALUES('11','bonjour','20')"); System. out.println("OK..."); } catch (Exception e) { System. out.println("Errrrreur..."+e.getMessage()); } } }
Partager