Hello i want to acess data from my mysql server
in javascript. But i have no clue how to do so.
I am running tomcat so it is not handy to use php.
Can someone please help me !
I thought maybe there is some way to get the variables
from my servlet, but it seems not possible to get
javascript connected to java or is there ?
var blueDates = magic way to get data from my mysql server;
Greetings,
Rick
You have to implement a servlet that returns the data from mysql. A good way to do so is to implemente a servlet that returns a JSON object containing the mysql data.
Once this is done use AJAX to ask the servlet for the data.
There is a lot of information about implementing this. After all this is a minimal REST implementation for a GET request. Just ask Stackoverflow or Google.
Related
I am very new in AJAX/JQuery. I have problem with following thing. I am hoping to get some information and suggestion on following thing.
I have data real time generated data (eg. xyz) in my localhost server which i have programmed using Java.
My question is
Is it possible to retrieve this data ( i.e. xyz) from localhost server using AJAX/JQuery to JavaScript????
What function does that and how do we do that ?? Plz show me with example..it will be very great help for me
Ajax is something just like common HTTP requests, but it is sent inside your jvascript code and can be moderate with javascript.
Independent of the server side script you have, you can use Ajax to send requests and get responses from that server side application (In server side it can be treated as a simple HTTP reauest).
Finally this is a helpful toturial: W3School Tutorial , and if you are familiar with JQuery or using it in your current project, it is the reference for JQuery Ajax: JQuery.ajax, both with samples.
i had used eclipse to develop an android apps that can allow user to register.
after they register successfully and go into the main page, they are able to see their own profile which consists of the details they keyed in during register. (The details will saved into phpmyadmin)
any method can retrieve those details from the database and display it on the profile page? (i am using php and java)
thanks for answering..
You can always use "Zend AmF" or "AMF PHP" for comunicating with the app, binary.
http://www.silexlabs.org/amfphp/
http://framework.zend.com/manual/1.12/en/zend.amf.html
or amf mixed with codeigniter
https://github.com/EllisLab/CodeIgniter
Then use:
- http://code.google.com/p/klio-mobile-dataservice/
to connect with your server
You need to have a server, like a Tomcat, or anyother server, to which you will post the data
The Servlet or the PHP script, will read the values, store them in database.
The Android application will get the data from another Servlet or a PHP page, using a HTTP Get request, and show it on the screen.
You can alternatively, store the keys locally in the device, using SharedPreferences, and get them in the next screen.
You have to write a php script wich parses data from your database into for example JSON-Format. If you had parsed the json you can use the JSON parser in android to show he content in your activitys.
Here is a very nice tutorial for json parsing in android:
http://www.androidhive.info/2012/01/android-json-parsing-tutorial/
Basically you have to create Web Service in PHP or Java and from there you need to get your data.
You have to create Restful API which returns data in the form of XML or JSON and you need to parse those data at android end. By this way you can get your data from PHP.
Here is the best resource which i found when i was searching for this kind of scenario. The author has explained very well in this and you will get very good idea about the scenario. Also provide sample code for reference.
Refer this link.
Hope this helps!
How to connect to Oracle with a Java program?
you need to go through JDBC tutorial.
You should never really have anything other than presentation logic in JSP. I am worried that thinking of connecting to Database from JSP is a bad idea. Use Servlets with JSP. Keep JDBC connectivity in servlet and presentation logic in JSP.
As long as solving your problem stands, you can just embed Java code in JSP as mentioned here Establishing a Connection. For Oracle, use URL like
jdbc:oracle:thin://[host][:port]/SID
See this worked example.
I should point out that doing database transaction inside a JSP is not a good idea. It is generally thought to be better to do the request argument processing and database heavy lifting in a pure Java servlet within your webapp, attach the results as request attributes, and then use the request dispatcher to 'forward' to or 'include' the JSP.
One problem with doing database stuff in the JSP itself is that it is difficult to report problems properly. For instance the JSP will most likely commit the response right at the beginning, making it impossible to change the response status code and/or headers. The net result could be the delivery of a truncated page with the wrong status code.
You can try this:
connect = DriverManager.getConnection("jdbc:oracle:thin:xyz/ abc#(descrip
tion=(address_list=(address=(protocol=tcp) (host=servername or ip)
(port=1521))) (source_route=yes)(connect_data=(sid=ora)))");
I have some GWT application that run on the server.
we are subscripting with some solution that pings this application in a regular interval of time.
The point is, this solution (service) checks the returned response from the server to contain some pre-defined keywords.
But as you know, GWT return plain empty HTML page with the data contained in the .js file.
So, the Ping service will not be able to exmain the pre-defined keywords, Is this statement true??
And if this is ture, cannot we find any workaround solution to solve such problem?
Thanks.
The problem you are facing is related to the crawlabitlity of AJAX applications - Google has some pointers for you :) Generally, you need a headless browser on the server to generate the output you'd normally see in the browser, for example see HtmlUnit.
Only the initial container page and the loader script that it embeds are HTML & JS. Afterwards, you use GWT's RPC mechanism to exchange Java objects with the server, or Ajax (eg. RequestBuilder) to exchange any kind of data with the server. you name it: JSON, XML, plain text, etc.
I want to access a MySQL database from Java, but remote connection is disabled by the host.
So I will send the data to PHP and then PHP will locally access the database.
The data is pretty big (about 2~4kb)
I've never done this before.
What should I do?
Probably the best way would be to write a web service in PHP that you call from Java.
Another somewhat easier way would be to use the HttpURLConnection class to simply do a POST of the data to the PHP page.
If the PHP page is publicly accessible, you'd want to make sure you have some kind of authentication mechanism in place and use HTTPS as well.
Http web-services
Sounds like your only option is to create a Web Service. You can use Apache's HttpClient in Java to create requests and have your PHP return a response that you can easily parse. Depending on what you are trying to do, an XML response might be overkill. I've used JSON in the past if I know exactly what I am getting back.
I assume the Java program will be the client. I think the simplest would be to just create a simple PHP page, POST any possible parameters to that page from Java, and return the data as a JSON structure.
There are a number of JSON tools for Java and PHP listed on JSON page: http://json.org/
You might want to have a look to Thrift:
http://incubator.apache.org/thrift/
Are you saying that you are going to run java from php, so that php has the handle to the mysql database and you will pass the data to java?
check out java php bridge