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;








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.










share|improve this question
























  • 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

















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.










share|improve this question
























  • 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













0












0








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.










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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

















  • 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












1 Answer
1






active

oldest

votes


















0














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






share|improve this answer























  • 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










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
);



);













draft saved

draft discarded


















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









0














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






share|improve this answer























  • 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















0














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






share|improve this answer























  • 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













0












0








0







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






share|improve this answer













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







share|improve this answer












share|improve this answer



share|improve this answer










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

















  • 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








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.



















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현