• Post Reply Bookmark Topic Watch Topic
  • New Topic

Connection to JDBC

 
Kajol Shroff
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everybody,
I am working on a application using applets where in i nee to send the data from the applet to the database/ or in the file format. ..the database i will be using is MySQl..
Can anybody help me out in this.
I dont know how to go about it.. as i am beginner.....
Please get back to
Waiting for the reply...
Kajol
 
Ashwin Desai
Ranch Hand
Posts: 124
 
Kajol Shroff
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ashwin,
Sorry to say that but it wasnt of much help to me .. can u please help me out..i am really set on deadlines...
Please i need help.
Kajol
 
jos xavier
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Kajol Shroff:
Hi Ashwin,
Sorry to say that but it wasnt of much help to me .. can u please help me out..i am really set on deadlines...
Please i need help.
Kajol

hi kajol,
You need to open a DataOutputStream in your applet. Send the data through this outputstream to a servlet who in turn will will collect the data from the request object....
If the data is small then send the data with the url using the urlencode .
i hope you could use this code :
URL url;
URLConnection ucon;
String CustStr= tfCustCode.getText();

try {

url = new URL("http://90.0.0.3:8080/servlet/DataQuestServlet");
CustCode= URLEncoder.encode("Cust")+ "=" + URLEncoder.encode(CustStr) ;
ucon = url.openConnection();
ucon.setDoOutput(true);
ucon.setDoInput(true);
ucon.setUseCaches(false);
ucon.setRequestProperty("Content-type","application/x-www-form-urlencoded");
DataOutputStream outStream = new DataOutputStream(ucon.getOutputStream());
outStream.writeBytes(CustCode);
outStream.flush();
outStream.close();

//if you want to get data from the servlet use this code
InputStreamReader inStream = new InputStreamReader(ucon.getInputStream());
int EOFile = inStream.read();

while (EOFile !=-1) {
MsgDisplay.append(String.valueOf((char)EOFile));
EOFile = inStream.read();

}
inStream.close();

} //-- try

catch (MalformedURLException me) {
System.out.println(me);

} //-- catch


catch (IOException io) {

System.out.println(io);

} //-- catch
The servlet code can be something like this :
// but you have to improvise the code

public void doPost(HttpServletRequest req, HttpServletResponse Res)throws ServletException, IOException {

Res.setContentType("text/html");
PrintWriter out = Res.getWriter();
CustCode = req.getParameter("Cust");
System.out.println("value of custcode" +CustCode);
out.println(CustCode);
}//----doGet


} //----close DataQuestServlet
Hope it helps !!
jose xavier
 
Kajol Shroff
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jos,
Sorry to bother u more.Can u please send me the complete code so that I get the exact thing as to what it is..Is it possible for you to explain the code to me.
Kajol
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!