protected
void
doPost(HttpServletRequest request, HttpServletResponse response)
throws
ServletException, IOException {
String data =
null
;
InputStream is = request.getInputStream();
ByteArrayOutputStream baos =
new
ByteArrayOutputStream();
byte
buf[] =
new
byte
[
1024
];
int
len;
while
((len = is.read(buf))>
0
){
baos.write(buf,
0
, len);
}
data =
new
String(baos.toByteArray(),
"UTF-8"
);
System.out.println(data);
Connection connect=
null
;
Statement st=
null
;
String url = "jdbc:sqlserver:
String userid =
"sa"
;
String passwd =
""
try
{
Class.forName(
"com.microsoft.sqlserver.jdbc.SQLServerDriver"
);
connect = DriverManager.getConnection(url,userid,passwd);
st = connect.createStatement();
JSONArray jsonarr =
new
JSONArray(data);
for
(
int
i=
0
;i<jsonarr.length();i++){
JSONObject jsonobj = jsonarr.getJSONObject(i);
System.out.println(jsonobj.getString(
"User_ID"
));
System.out.println(jsonobj.getString(
"Description"
));
String sql =
"DECLARE "
+
"@return_value int EXEC "
+
"@return_value = [dbo].[PDA_BreakDown_InsertUpdate] "
+
"@BD_ID = NULL,"
+
"@FObject_ID = N'"
+jsonobj.getString(
"FObject_ID"
)+
"', "
+
"@Description = N'"
+jsonobj.getString(
"Description"
)+
"',"
+
"@User_ID = N'"
+jsonobj.getString(
"User_ID"
)+
"'"
;
boolean
resut = st.execute(sql);
System.out.println(resut);
}
}
catch
(SQLException | ClassNotFoundException | JSONException e) {
e.printStackTrace();
response.setStatus(HttpURLConnection.HTTP_FORBIDDEN);
}
finally
{
try
{
if
(st!=
null
) st.close();
if
(connect!=
null
)connect.close();
}
catch
(SQLException e) {
e.printStackTrace();
}
}