using a button on a webpage to execute a java class
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Patrick_Geary
Posted On:   Tuesday, April 29, 2003 03:34 AM

Hi I have set up a java class called "TeamWin". It is for a fantasy football game. What this class does is add 5 points to the total in a database. What i am attempting to do is have a webpage for the administrator where he can just press a "Team Win" button and this will execute the java class. The java code i have is as follows package fantasyfootball; import java.sql.Connection; import java.sql.Statement; import java.sql.DriverManager; import java.sql.SQLException; import java.sql.ResultSet; import java.util.*; import java.beans.*; import java.net.URL; import java.sql.*; public class TeamWin {    More>>

Hi


I have set up a java class called "TeamWin". It is for a fantasy football game. What this class does is add 5 points to the total in a database. What i am attempting to do is have a webpage for the administrator where he can just press a "Team Win" button and this will execute the java class. The java code i have is as follows


			
package fantasyfootball;

import java.sql.Connection;
import java.sql.Statement;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.ResultSet;
import java.util.*;
import java.beans.*;
import java.net.URL;
import java.sql.*;

public class TeamWin
{
public static void main(String args[])
{
Vector win = new Vector();
Vector lose = new Vector();
Vector draw = new Vector();

try{//start of try
//connect to database
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Drivers loaded");
String url = "jdbc:odbc:fantasyfootball";
Connection con = DriverManager.getConnection(url,"root","");
System.out.println("Connection established");

Statement stmt = con.createStatement();
System.out.println("Statement created");
ResultSet res = stmt.executeQuery("SELECT winning_teams FROM results");

Statement updt;
//list the returned rows
while(res.next())
{
updt = con.createStatement();


updt.executeUpdate("UPDATE teams SET points_scored=(points_scored+5) WHERE team_name='"+res.getString("winning_teams")+"'");
updt.close();


}



//clean up
stmt.close();
con.close();
}//end of try

catch(Exception e){//start of catch
System.out.println(e.getMessage());
e.printStackTrace();
}//end of catch
}


String team_name;
int points_scored=0;

}


Any help would be greatly appreciated


Thanks

   <<Less

Re: using a button on a webpage to execute a java class

Posted By:   Matan_Amir  
Posted On:   Tuesday, June 10, 2003 02:51 AM

One way to do it would be to create a Java Applet around your class. It can even be a hidden applet that has no user interface. Create a public function that does the functionality you want (basically like your main method)...and embed the applet in your html page. Through javascript (make an html button that calls the javascript with the onclick event) you'll be able to access the applet and call your function.



That is one solution. I left out the exact details but feel free to ask if you have any specific questions on one of the steps.



Hope that helps,

Matan
About | Sitemap | Contact