Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Aryya Dwisatya W
IF3230-Tugas-Besar-Sister-2015
Commits
c8b6477f
Commit
c8b6477f
authored
Apr 27, 2015
by
adwisatya
Browse files
Find offers, belum di tes
parent
c312a4a7
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/server/src/thealchemist/Client.java
View file @
c8b6477f
...
...
@@ -174,7 +174,7 @@ public class Client extends Thread{
case
"sendfind"
:
cmdSendFind
(
utility
.
JSONtoString
(
"token"
,
cmd
),
Integer
.
parseInt
(
utility
.
JSONtoString
(
"item"
,
cmd
)));
break
;
/* 12 belum */
/* 12
-
belum
di tes
*/
case
"findoffer"
:
cmdFindOffer
(
new
Integer
(
utility
.
JSONtoString
(
"itemid"
,
cmd
)));
break
;
...
...
@@ -407,23 +407,13 @@ public class Client extends Thread{
}
/* Sukses */
public
void
cmdFindOffer
(
int
itemId
)
throws
IOException
,
NoSuchAlgorithmException
,
JSONException
{
String
response
=
""
;
String
request
=
""
;
Socket
miniSocket
=
new
Socket
(
URL
,
dbPort
);
JSONObject
obj
=
new
JSONObject
();
obj
.
put
(
"method"
,
"findoffer"
);
obj
.
put
(
"token"
,
token
);
obj
.
put
(
"item"
,
new
Integer
(
itemId
));
PrintWriter
out
=
new
PrintWriter
(
new
BufferedWriter
(
new
OutputStreamWriter
(
miniSocket
.
getOutputStream
())));
out
.
println
(
obj
);
out
.
println
();
out
.
flush
();
BufferedReader
in
=
new
BufferedReader
(
new
InputStreamReader
(
miniSocket
.
getInputStream
()));
response
=
org
.
apache
.
commons
.
io
.
IOUtils
.
toString
(
in
);
in
.
close
();
try
{
obj
=
database
.
getOfferList
(
itemId
);
}
catch
(
ClassNotFoundException
ex
)
{
Logger
.
getLogger
(
Client
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
}
sendToClient
(
obj
.
toString
());
}
/* Sukses */
public
String
cmdSendAccept
(
String
token
,
String
offer_token
)
throws
IOException
,
NoSuchAlgorithmException
,
JSONException
{
...
...
src/server/src/thealchemist/Database.java
View file @
c8b6477f
...
...
@@ -251,6 +251,37 @@ public class Database {
}
return
objToSent
;
}
public
JSONObject
getOfferList
(
int
itemid
)
throws
ClassNotFoundException
,
JSONException
{
Connection
conn
=
null
;
Statement
statement
=
null
;
ResultSet
rs
;
JSONObject
objToSentFinal
=
new
JSONObject
();
JSONObject
objToSent
=
new
JSONObject
();
JSONArray
objArr
=
new
JSONArray
();
try
{
Class
.
forName
(
driver
);
conn
=
DriverManager
.
getConnection
(
url
+
dbName
,
username
,
password
);
statement
=
conn
.
createStatement
();
rs
=
statement
.
executeQuery
(
"SELECT `offered_item`,`n1`,`demanded_item`,`n2` from offers WHERE offered_item="
+
itemid
);
while
(
rs
.
next
()){
objToSent
.
put
(
""
,
rs
.
getInt
(
"offered_item"
));
objToSent
.
put
(
""
,
rs
.
getInt
(
"n1"
));
objToSent
.
put
(
""
,
rs
.
getInt
(
"demanded_item"
));
objToSent
.
put
(
""
,
rs
.
getString
(
"n2"
));
objArr
.
put
(
objToSent
);
}
System
.
out
.
println
(
objArr
.
toString
());
statement
.
close
();
conn
.
close
();
objToSentFinal
.
put
(
"status"
,
"ok"
);
objToSentFinal
.
put
(
"offers"
,
objArr
);
}
catch
(
SQLException
e
){
objToSentFinal
.
put
(
"status"
,
"error"
);
e
.
printStackTrace
();
}
return
objToSentFinal
;
}
public
JSONObject
mixItems
(
String
token
,
String
itemid1
,
String
itemid2
)
throws
ClassNotFoundException
,
InstantiationException
,
IllegalAccessException
,
SQLException
,
NoSuchAlgorithmException
{
Connection
conn
=
null
;
Statement
statement
=
null
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment