Results 1 to 1 of 1

Thread: Java Help

  1. #1
    Hmmm bed
    Join Date
    Jul 2003
    Posts
    441
    Thanks
    5
    Thanked
    0 times in 0 posts

    Java Help

    Hi, right, I have created the following code below, I am trying to convert it into a Bean by creating a manifest file and generating a jar file, however, it just does not seem to work, not allowing me to use it once the jar file is loaded through BeanBuilder, so i fear the error may lie in this code somewhere,

    any help would be greatly appreciated,

    Thanks for your time.


    Code:
    import java.io.*;
    import java.util.*;
    import java.sql.*;
    
    public class MatchResults implements Serializable
    {
    	private int resOppScore=0;
    	private int resClubScore=0;
    
    	public static void main (String args[])
    	{
    		MatchResults matchRes = new MatchResults();
    	}
    
    	public MatchResults()
    	{
    		System.out.println("tester");
    	}
    
    	public void insertNew(String opponents,String homeOrAway,int clubScore, int oppScore)
    	{
    		Connection link = null;
    		Statement statement = null;
    		Scanner input = new Scanner(System.in);
    		boolean matchFound;
    
    
    		matchFound=getData(opponents,homeOrAway);
    
    		if (!matchFound)
    		{
    			try
    			{
    				Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    				link = DriverManager.getConnection("jdbc:odbc:ClubData","","");
    			}
    			catch(ClassNotFoundException e)
    			{
    				System.out.println("* Unable to load driver! *");
    				System.exit(1);
    			}
    			catch(SQLException e)
    			{
    				System.out.println("* Cannot connect to database! *");
    				System.exit(1);
    			}
    
    			try
    			{
    				statement = link.createStatement();
    				String insert = "INSERT INTO Results VALUES ('"+ opponents + "','" + homeOrAway + "'," + clubScore + "," + oppScore + ")";
    				int result = statement.executeUpdate(insert);
    
    				if (result==0)
    					System.out.println("\t\tInsertion Failed!");
    				else
    					System.out.println("\t\tRecords Inserted");
    			}
    			catch(SQLException e)
    			{
    				System.out.println("* Cannot execute query! *");
    				e.printStackTrace();
    				System.exit(1);
    			}
    
    			finally
    			{
    				try
    				{
    					link.close();
    				}
    				catch(SQLException e)
    				{
    					System.out.println("* Unable to disconnect! *");
    					e.printStackTrace();
    				}
    			}
    		}
    		else
    			System.out.println("\n\t\t* Match Already Exists - Insertion Cancelled *");
    	}
    
    	public boolean getData(String opponents, String homeOrAway)
    	{
    		Connection link = null;
    		Statement statement = null;
    		ResultSet results = null;
    		boolean matchFound = false;
    
    		try
    		{
    			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    			link = DriverManager.getConnection("jdbc:odbc:ClubData","","");
    		}
    		catch(ClassNotFoundException e)
    		{
    			System.out.println("* Unable to load driver! *");
    			System.exit(1);
    		}
    		catch(SQLException e)
    		{
    			System.out.println("* Cannot connect to database! *");
    			System.exit(1);
    		}
    
    		try
    		{
    			statement = link.createStatement();
    			results = statement.executeQuery(	"SELECT * FROM Results "
    												+ "WHERE opponents = '"+ opponents +"' "
    												+ "AND homeOrAway= '" + homeOrAway + "'");
    		}
    		catch(SQLException e)
    		{
    			System.out.println("* Cannot execute query! *");
    			e.printStackTrace();
    			System.exit(1);
    		}
    
    		try
    		{
    
    
    			while (results.next())
    			{
    				System.out.println("\n\t\t- Match Information -\n");
    				int opponentScore = results.getInt(4);
    				int clubScore = results.getInt(3);
    
    				System.out.print("\t\tScore - ");
    				System.out.println("Us:" + clubScore + " " + results.getString(1) + ":" + opponentScore + "\n");
    
    				if(clubScore>opponentScore)
    					System.out.println("\t\tHome Win\n");
    				else
    					if(clubScore==opponentScore)
    						System.out.println("\t\t- Draw -\n");
    					else
    						System.out.println("\t\t- Away Win -\n");
    
    				matchFound=true;
    
    				resOppScore = opponentScore;
    				resClubScore = clubScore;
    			}
    
    		}
    		catch(SQLException e)
    		{
    			System.out.println("* Error retrieving data! *");
    			e.printStackTrace();
    			System.exit(1);
    		}
    
    		finally
    		{
    			try
    			{
    				link.close();
    			}
    			catch(SQLException e)
    			{
    				System.out.println("* Unable to disconnect! *");
    				e.printStackTrace();
    			}
    		}
    
    		return matchFound;
    
    	}
    
    	public int getClubScore(String opponents, String homeOrAway)
    	{
    		getData(opponents,homeOrAway);
    		return resClubScore;
    	}
    
    	public int getOppScore(String opponents, String homeOrAway)
    	{
    		getData(opponents,homeOrAway);
    		return resOppScore;
    	}
    
    	public void setNewMatch(String opponents, String homeOrAway, int clubScore, int oppScore)
    	{
    		insertNew(opponents,homeOrAway,clubScore,oppScore);
    	}
    }
    Last edited by Basher; 24-03-2005 at 05:24 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Best book to learn JAVA 2?
    By Taz in forum Software
    Replies: 16
    Last Post: 27-08-2005, 08:54 PM
  2. JAVA BYTEVER and FEMAD (virus type thing)
    By Kumagoro in forum Software
    Replies: 5
    Last Post: 28-12-2004, 04:56 PM
  3. Potential HUGE source of free Java games / apps
    By PriestJPN in forum Smartphones and Tablets
    Replies: 4
    Last Post: 03-11-2004, 01:59 AM
  4. Java
    By Jonny M in forum Software
    Replies: 8
    Last Post: 24-12-2003, 02:33 PM
  5. Java vs .NET
    By DaBeeeenster in forum Software
    Replies: 2
    Last Post: 11-09-2003, 02:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •