• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Connection to JDBC

 
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Refer to http://www.javaranch.com/ubb/Forum23/HTML/000706.html
 
Kajol Shroff
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Opportunity is missed by most people because it is dressed in overalls and looks like work - Edison. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic