How to insert data into MySQL through a URL? - java

So I have a MySQL db called "Example". In the db, I have a table with a row called "Rank" and "Name". I want to be able to input "Rank" and "Name" values into the db through URL.
I have made a Tomcat server through Eclipse, and would like help on the java code in order to use the parameters to send data to the db.
Thanks in advance!

Java - sending HTTP parameters via POST method easily
The question itself shows a 'GET' method. the accepted answer shows a 'POST' method.
All the handling should be done on your server.
This is a code for sending it the right values to the server.
Do you need help with the server itself?
I know how to do that in php, if that helps you

Related

AEM Human Translation Getting The Response From Server?

I use bootstrap translation framework (Git : https://forums.adobe.com/external-link.jspa?url=https%3A%2F%2Fgithub.com%2FAdobe-Marketing-Cloud%2Faem-translation-framework-bootstrap-connector%2Fblob%2Fmaster%2Fbundle%2Fsrc%2Fmain%2Fjava%2Fcom%2Fadobe%2Fgranite%2Ftranslation%2Fconnector%2Fbootstrap%2Fcore%2Fimpl%2FBootstrapTranslationServiceImpl.java) : I use this method uploadTranslationObject for posting to my server and one request is completed.
I just have a small doubt like i use human translation the response will be coming after some X delay time.Now i am wondering how do i get the response once the translated response is ready from my server??
I have the logic of returning the translated xml on my server but question is how do i return it?? I mean where should my server post on some api or will ame keeps constantly looking for the response?
Can someone please let me know with a small code or a existing method? I need to find in which method of the code will the response from server will be handled ??
Thanks In Advance.
You will have to monitor the status of the Documents(TranslationObjects). When you upload the TO for translation via uploadTranslationObject() change the status of the TO to 'SUBMITTED' or 'TRANSLATION_IN_PROGRESS'.
Then in the getTranslationObjectStatus() you will make request to your server to know if the TO are translated or not. If the TO is translated then you can change the status of the TO to 'TRANSLATED'. The method getTranslationObjectStatus() will return TranslationStatus as TRANSLATED, this will invoke getTranslatedObject() where you will download the translated TO and return it as InputStream.
Note: getTranslationObjectStatus() and other status update helper methods will be called when you refresh the TranslationJob Page.

JAVA Apache Jena Fuseki: Create Endpoint via API, Retrieve all endpoints via API

i have two questions related to Apache Jena Fuseki.
The first one is:
I need to create an endpoint using the API (from java code, not from Fuseki UI). For "endpoint" i mean the dataset that fuseki allow to create using the UI, from http://localhost:xxxx/. I also need to make it persistent.
The second one:
consider that we have a list of dataset already created. I want to get the "label" of each existing endpoint (ex: dataset1, dataset56, testDataset ....).
I know how to query and update data from a specified endpoint, but i have no idea on how manage datasets (create/delete and also get the label).
Any suggestion will be appreciated.
EDIT1:
I've found a workaround
Retrieve dataset list by sending a GET request to http://localhost:3030/$/server
Create dataset by sending a POST request to http://localhost:3030/$/datasets
The following POST parameters must be set: "dbName=/dataseName&dbType=tdb"
dbType can be set either to mem (non persistent dataset) or tdb (persistent dataset).
Still trying to find a way to get the same results using a Jena API call.

Exchange authorizational code works only once - Oauth2.0

I'm trying to implement this code. https://developers.google.com/drive/web/credentials#retrieve_oauth_20_credentials
I have my client id and client_secrets json for webapps, because I'm extracting some values from a spreadsheet, everything is ok and I already have spreadsheet's data in my application. But my question is How can I make to re-use that authorization code multiple times?, because I have to extract more data from that spreadsheet, my URL is http://localhost:8080/cluster/?state=/profile&code=xxxxxxx but for example when I try to refresh that page this error appears.
An error occurred: com.google.api.client.auth.oauth2.TokenResponseException: 400 Bad Request
{
"error" : "invalid_grant",
"error_description" : "Code was already redeemed."
}
I have the same implementation of the url, but the only difference is I changed this methods storeCredentials(userId, credentials) - getStoredCredentials(userId) and put that values into a db table.
So, How can I implement 'exchange authorization code'? and how can I link my application to the new url?
Thanks for your help! :D
First at all, following the protocol the authorization code MUST BE used once, so the auth server must invalidate it after the first use.
If you want to use it for another part of your implementation, you can save it, use it and send a 302 redirect to your other page witch use your getStoredCredentials method

why we need to use get method inside a java file #RequestMapping(method = RequestMethod.GET)

In generally while sending form data from the ui pages we are using method="GET" or method="POST" in the form tag then what is the use of these methods in the server side programs. I am using these methods in spring while calling the methods in the controller #RequestMapping(method = RequestMethod.GET)
Can anyone explain what is the real use of get or post methods in server side code
Loosely speaking, if the purpose of your method is to retrieve data from the server use GET. e.g. getting information to display on the client.
If you are sending data to the server use POST. e.g. sending information to the server to be saved on a database somewhere.
There is a limit to the size of data you can send to the server with a GET request.
The server side GET or POST is used to specify what the server expects to receive in order to accept the request. The client side GET or POST is used to specify what will be sent to the server. These two must match. You cannot send a GET request when server expects a POST and vice-versa.
When you are building a server application, it is important to know the appropriate request type to use, which by itself is a whole big different topic which you should research if it is you the one that builds the server side part.

How to protect servlet response data when directly accessed using URL

In my application I have used JSON auto suggest functionality to suggest name of user id when stored in cache.
So when ever I try to hit the URL the response is getting back the fully qualified email address, PFB -
Request - https://wwwsampleweb.com/tc/servlet/AjaxServiceServlet?qtc=james*
it is returning the response -
{identifier:'name', items: [ {name:'james.goodlife#abc.com', label:'james.goodlife#abc.com'}]}
How to stop the response when directly accessing the URL?
I have tried to verify the session but this servlet is used for auto sugggesting the username while logging in which means session is not created status. Also we can block the IP but we cannot block all IPs.
Could you please assist me how we can stop this?
Thanks!
I'm missing the value of username-suggesting at a login-form, but anyway;
I assume that you are requesting the data using a GET-request?
If you would like to prevent anyone from accessing the URL directly and retrieving data, you could use a POST-request and then only return data when the page is accessed through a POST-request (optionally combined with the session-check).
Please keep in mind that this is not a bullet-proof way of preventing use.

Categories