How to Send Variables from Java class to PHP script?How to parse JSON in JavaHow do I efficiently iterate over each entry in a Java Map?How can I prevent SQL injection in PHP?Java inner class and static nested classHow do I call one constructor from another in Java?How do I read / convert an InputStream into a String in Java?How do I generate random integers within a specific range in Java?Deleting an element from an array in PHPHow to get an enum value from a string value in Java?How do I determine whether an array contains a particular value in Java?How do I convert a String to an int in Java?
How can one write good dialogue in a story without sounding wooden?
definition of "percentile"
How can an advanced civilization forget how to manufacture its technology?
Who has taken "my" Managed package namespace? Can we find out?
Why isn't there research to build a standard lunar, or Martian mobility platform?
Was I subtly told to resign?
How to know whether a Tamron lens is compatible with Canon EOS 60D?
Do you know your 'KVZ's?
Are randomly-generated passwords starting with "a" less secure?
ESTA: "Is your travel to the US occurring in transit to another country?" when going on a cruise
Can fluent English speakers distinguish “steel”, “still” and “steal”?
Can I play a first turn Simic Growth Chamber to have 3 mana available in the second turn?
How were Martello towers supposed to work?
Book where the stars go black due to aliens stopping human observation collapsing quantum possibilities
What's the minimum number of sensors for a hobby GPS waypoint-following UAV?
Why do people keep referring to Leia as Princess Leia, even after the destruction of Alderaan?
What's the maximum time an interrupt service routine can take to execute on atmega328p?
Professor falsely accusing me of cheating in a class he does not teach, two months after end of the class. What precautions should I take?
Managing and organizing the massively increased number of classes after switching to SOLID?
How can I effectively communicate to recruiters that a phone call is not possible?
Is an acid a salt? Why (not)?
Why was hardware diversification an asset for the IBM PC ecosystem?
Is Arc Length always irrational between two rational points?
Print the last, middle and first character of your code
How to Send Variables from Java class to PHP script?
How to parse JSON in JavaHow do I efficiently iterate over each entry in a Java Map?How can I prevent SQL injection in PHP?Java inner class and static nested classHow do I call one constructor from another in Java?How do I read / convert an InputStream into a String in Java?How do I generate random integers within a specific range in Java?Deleting an element from an array in PHPHow to get an enum value from a string value in Java?How do I determine whether an array contains a particular value in Java?How do I convert a String to an int in Java?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
So, I'm trying to recreate an older PHP program of mine partially in Java however I've hit a roadblock in my code. No matter what I try to do, I can't seem to send information from my Java class to my PHP script. The PHP script is hosted on an online server, while my Java class is on a client machine.
My code goes as following:
String query = SearchTextBox.getText();
Connection conn = DriverManager.getConnection(
"jdbc:mysql://localhost/wc_wca?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC","root","pass" );
String sql = "SELECT * FROM Persons WHERE id = ?";
PreparedStatement ps = conn.prepareStatement(sql);
ps.setString(1, query);
ResultSet rs = ps.executeQuery();
while (rs.next())
try
URL url = new URL("http://worldcubers.com/setup/index.php");
URLConnection con = url.openConnection();
String name = rs.getString("name");
String id = rs.getString("id");
// activate the output
con.setDoOutput(true);
PrintStream printstream = new PrintStream(con.getOutputStream());
// send your parameters to your site
printstream.print("&name=" + name);
printstream.print("&id=" + id);
// we have to get the input stream in order to actually send the request
con.getInputStream();
// close the print stream
ps.close();
catch (IOException ex)
Logger.getLogger(MainUI.class.getName()).log(Level.SEVERE, null, ex);
initAndShowGUI();
this.dispose(); //to close the current jframe
In the PHP script, the lines that access the variables are the following:
$s = $_SESSION['name'];
$q = $_SESSION['id'];
I've tried many different articles here on StackOverflow, but to no avail, no matter what I try, I can't seem to send the name & id variables to the PHP script.
java php mysql
add a comment |
So, I'm trying to recreate an older PHP program of mine partially in Java however I've hit a roadblock in my code. No matter what I try to do, I can't seem to send information from my Java class to my PHP script. The PHP script is hosted on an online server, while my Java class is on a client machine.
My code goes as following:
String query = SearchTextBox.getText();
Connection conn = DriverManager.getConnection(
"jdbc:mysql://localhost/wc_wca?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC","root","pass" );
String sql = "SELECT * FROM Persons WHERE id = ?";
PreparedStatement ps = conn.prepareStatement(sql);
ps.setString(1, query);
ResultSet rs = ps.executeQuery();
while (rs.next())
try
URL url = new URL("http://worldcubers.com/setup/index.php");
URLConnection con = url.openConnection();
String name = rs.getString("name");
String id = rs.getString("id");
// activate the output
con.setDoOutput(true);
PrintStream printstream = new PrintStream(con.getOutputStream());
// send your parameters to your site
printstream.print("&name=" + name);
printstream.print("&id=" + id);
// we have to get the input stream in order to actually send the request
con.getInputStream();
// close the print stream
ps.close();
catch (IOException ex)
Logger.getLogger(MainUI.class.getName()).log(Level.SEVERE, null, ex);
initAndShowGUI();
this.dispose(); //to close the current jframe
In the PHP script, the lines that access the variables are the following:
$s = $_SESSION['name'];
$q = $_SESSION['id'];
I've tried many different articles here on StackOverflow, but to no avail, no matter what I try, I can't seem to send the name & id variables to the PHP script.
java php mysql
ps.close();
doesn't close the print stream...
– shmosel
Mar 26 at 3:34
What does it do, then?
– William Siauw
Mar 26 at 3:40
1
Take another look and tell me.
– shmosel
Mar 26 at 3:45
add a comment |
So, I'm trying to recreate an older PHP program of mine partially in Java however I've hit a roadblock in my code. No matter what I try to do, I can't seem to send information from my Java class to my PHP script. The PHP script is hosted on an online server, while my Java class is on a client machine.
My code goes as following:
String query = SearchTextBox.getText();
Connection conn = DriverManager.getConnection(
"jdbc:mysql://localhost/wc_wca?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC","root","pass" );
String sql = "SELECT * FROM Persons WHERE id = ?";
PreparedStatement ps = conn.prepareStatement(sql);
ps.setString(1, query);
ResultSet rs = ps.executeQuery();
while (rs.next())
try
URL url = new URL("http://worldcubers.com/setup/index.php");
URLConnection con = url.openConnection();
String name = rs.getString("name");
String id = rs.getString("id");
// activate the output
con.setDoOutput(true);
PrintStream printstream = new PrintStream(con.getOutputStream());
// send your parameters to your site
printstream.print("&name=" + name);
printstream.print("&id=" + id);
// we have to get the input stream in order to actually send the request
con.getInputStream();
// close the print stream
ps.close();
catch (IOException ex)
Logger.getLogger(MainUI.class.getName()).log(Level.SEVERE, null, ex);
initAndShowGUI();
this.dispose(); //to close the current jframe
In the PHP script, the lines that access the variables are the following:
$s = $_SESSION['name'];
$q = $_SESSION['id'];
I've tried many different articles here on StackOverflow, but to no avail, no matter what I try, I can't seem to send the name & id variables to the PHP script.
java php mysql
So, I'm trying to recreate an older PHP program of mine partially in Java however I've hit a roadblock in my code. No matter what I try to do, I can't seem to send information from my Java class to my PHP script. The PHP script is hosted on an online server, while my Java class is on a client machine.
My code goes as following:
String query = SearchTextBox.getText();
Connection conn = DriverManager.getConnection(
"jdbc:mysql://localhost/wc_wca?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC","root","pass" );
String sql = "SELECT * FROM Persons WHERE id = ?";
PreparedStatement ps = conn.prepareStatement(sql);
ps.setString(1, query);
ResultSet rs = ps.executeQuery();
while (rs.next())
try
URL url = new URL("http://worldcubers.com/setup/index.php");
URLConnection con = url.openConnection();
String name = rs.getString("name");
String id = rs.getString("id");
// activate the output
con.setDoOutput(true);
PrintStream printstream = new PrintStream(con.getOutputStream());
// send your parameters to your site
printstream.print("&name=" + name);
printstream.print("&id=" + id);
// we have to get the input stream in order to actually send the request
con.getInputStream();
// close the print stream
ps.close();
catch (IOException ex)
Logger.getLogger(MainUI.class.getName()).log(Level.SEVERE, null, ex);
initAndShowGUI();
this.dispose(); //to close the current jframe
In the PHP script, the lines that access the variables are the following:
$s = $_SESSION['name'];
$q = $_SESSION['id'];
I've tried many different articles here on StackOverflow, but to no avail, no matter what I try, I can't seem to send the name & id variables to the PHP script.
java php mysql
java php mysql
edited Mar 26 at 3:39
William Siauw
asked Mar 26 at 3:28
William SiauwWilliam Siauw
114 bronze badges
114 bronze badges
ps.close();
doesn't close the print stream...
– shmosel
Mar 26 at 3:34
What does it do, then?
– William Siauw
Mar 26 at 3:40
1
Take another look and tell me.
– shmosel
Mar 26 at 3:45
add a comment |
ps.close();
doesn't close the print stream...
– shmosel
Mar 26 at 3:34
What does it do, then?
– William Siauw
Mar 26 at 3:40
1
Take another look and tell me.
– shmosel
Mar 26 at 3:45
ps.close();
doesn't close the print stream...– shmosel
Mar 26 at 3:34
ps.close();
doesn't close the print stream...– shmosel
Mar 26 at 3:34
What does it do, then?
– William Siauw
Mar 26 at 3:40
What does it do, then?
– William Siauw
Mar 26 at 3:40
1
1
Take another look and tell me.
– shmosel
Mar 26 at 3:45
Take another look and tell me.
– shmosel
Mar 26 at 3:45
add a comment |
1 Answer
1
active
oldest
votes
I think its high time you to start to think of using JSON to fix the problem you are facing
Also check here How to parse JSON in Java
I am using JSON to send variables back and forth for android app. I think the same can apply here.
Then think of using $_POST or $_GET but not $_SESSION
That helps with reading JSON, but how exactly would I write files from a client side Java app to a server hosted PHP script? Also, I only want to send 2 variables, is this the most optimal method for sending only 2 variables to the server?
– William Siauw
Mar 27 at 2:52
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55349444%2fhow-to-send-variables-from-java-class-to-php-script%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I think its high time you to start to think of using JSON to fix the problem you are facing
Also check here How to parse JSON in Java
I am using JSON to send variables back and forth for android app. I think the same can apply here.
Then think of using $_POST or $_GET but not $_SESSION
That helps with reading JSON, but how exactly would I write files from a client side Java app to a server hosted PHP script? Also, I only want to send 2 variables, is this the most optimal method for sending only 2 variables to the server?
– William Siauw
Mar 27 at 2:52
add a comment |
I think its high time you to start to think of using JSON to fix the problem you are facing
Also check here How to parse JSON in Java
I am using JSON to send variables back and forth for android app. I think the same can apply here.
Then think of using $_POST or $_GET but not $_SESSION
That helps with reading JSON, but how exactly would I write files from a client side Java app to a server hosted PHP script? Also, I only want to send 2 variables, is this the most optimal method for sending only 2 variables to the server?
– William Siauw
Mar 27 at 2:52
add a comment |
I think its high time you to start to think of using JSON to fix the problem you are facing
Also check here How to parse JSON in Java
I am using JSON to send variables back and forth for android app. I think the same can apply here.
Then think of using $_POST or $_GET but not $_SESSION
I think its high time you to start to think of using JSON to fix the problem you are facing
Also check here How to parse JSON in Java
I am using JSON to send variables back and forth for android app. I think the same can apply here.
Then think of using $_POST or $_GET but not $_SESSION
answered Mar 26 at 5:02
Jack SiroJack Siro
1
1
That helps with reading JSON, but how exactly would I write files from a client side Java app to a server hosted PHP script? Also, I only want to send 2 variables, is this the most optimal method for sending only 2 variables to the server?
– William Siauw
Mar 27 at 2:52
add a comment |
That helps with reading JSON, but how exactly would I write files from a client side Java app to a server hosted PHP script? Also, I only want to send 2 variables, is this the most optimal method for sending only 2 variables to the server?
– William Siauw
Mar 27 at 2:52
That helps with reading JSON, but how exactly would I write files from a client side Java app to a server hosted PHP script? Also, I only want to send 2 variables, is this the most optimal method for sending only 2 variables to the server?
– William Siauw
Mar 27 at 2:52
That helps with reading JSON, but how exactly would I write files from a client side Java app to a server hosted PHP script? Also, I only want to send 2 variables, is this the most optimal method for sending only 2 variables to the server?
– William Siauw
Mar 27 at 2:52
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55349444%2fhow-to-send-variables-from-java-class-to-php-script%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
ps.close();
doesn't close the print stream...– shmosel
Mar 26 at 3:34
What does it do, then?
– William Siauw
Mar 26 at 3:40
1
Take another look and tell me.
– shmosel
Mar 26 at 3:45