473,480 Members | 2,347 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How do I fix this error in my mini data acces code

2 New Member
my data ase has five field need enter new data(record)
after the last input when I press enter for the program to insert the five details I receive the following error and I cannot figure where I am going wron lease help!

"Exception in thread "main" java.lang.NullPointerException
at matchBeans.Results.entryMatchResults(Results.java: 113)
at matchBeans.Results.displayMenu(Results.java:51)
at matchBeans.Results.main(Results.java:17)"
================================================== =========
BELOW IS PART OF METHOD (CODE)
Expand|Select|Wrap|Line Numbers
  1. @SuppressWarnings("null")
  2.             public static void entryMatchResults(Scanner input)
  3.             { Statement statement=null;
  4.             Connection link;
  5.  
  6.                 Scanner input1 = new Scanner(System.in);
  7.                 int matchID;
  8.                 String opponents;
  9.                 String homeOraway;
  10.                 int clubScore,opponentsScore;
  11.  
  12.                 try
  13.                 {
  14.                     Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  15.                     DriverManager.getConnection(
  16.                                         "jdbc:odbc:ClubData","","");
  17.                 }
  18.                 catch(ClassNotFoundException cnfEx)
  19.                 {
  20.                     System.out.println("* Unable to load driver! *");
  21.                     System.exit(1);
  22.                 }
  23.                 catch(SQLException sqlEx)
  24.                 {
  25.                     System.out.println(
  26.                                 "* Cannot connect to database! *");
  27.                     System.exit(1);
  28.                 }
  29.  
  30.                 System.out.print(
  31.                         "\nEnter new match ID: ");
  32.                 matchID = input1.nextInt();
  33.                 System.out.print("\nEnter new first team name: ");
  34.                 opponents = input1.nextLine();
  35.  
  36.                 input1.nextLine();
  37.  
  38.                 System.out.print("\nEnter new second team name(s): ");
  39.                 homeOraway = input1.nextLine();
  40.                 System.out.print("\nEnter first team score: ");
  41.                 clubScore = input1.nextInt();
  42.                 System.out.print("\nEnter second team score: ");
  43.                 opponentsScore = input1.nextInt();
  44.  
  45.                 try
  46.                 {
  47.                     String insert = "INSERT INTO Results VALUES("
  48.                                     + matchID + ",'"
  49.                                     + opponents + "','"
  50.                                     + homeOraway + "',"
  51.                                     + clubScore + "'"
  52.                                     + opponentsScore +",)'";
  53.                      statement.executeUpdate(insert);
  54.  
  55.                     System.out.println("\nContents have been inserted:\n");
  56.  
  57.                 }
  58.                 catch(SQLException sqlEx)
  59.                 {
  60.                     System.out.println("* Cannot insert match details ! *");
  61.                     sqlEx.printStackTrace();
  62.                     System.exit(0);
  63.                 }
  64.                 closeDown();
  65.             }
  66.  
  67. private static void closeDown() 
  68. {
  69.     System.out.println("Cannot disconnect from data base:");
  70.  
  71. }
  72.  
Aug 11 '09 #1
2 1445
JosAH
11,448 Recognized Expert MVP
It would be nice if you'd showed us where those lines mentioned in the Exception stack trace are now ...

kind regards,

Jos
Aug 11 '09 #2
r035198x
13,262 MVP
Also prefer to use a PreparedStatement.
Aug 11 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

9
2716
by: Emmanuel Charruau | last post by:
Hi, I am looking for a class or any information which would allow me to make communicate mini-module in c++. I have been looking on the net for some examples of such implementation, but I did...
5
17855
by: Philippa | last post by:
I'm trying to access data in vba using the openrecordset command. The data in on a SQL Server 2000 database, and I have linked tables to that data. the Table I'm trying to access is one of these...
1
4825
by: Dakkar | last post by:
I'm getting this error when i execute my program ERROR Acces denied for user:'root@DAKKAR123' and when i write the line like this i dont take any error MyConn = new...
2
1485
by: Piotr Karwatka | last post by:
Hi! I have a little problem an qeustion. In .NET Windows Forms I can do something like that: - i have forms - Form1 Form2, on first form i have TextBox1 control on 2nd form I have Button1...
3
3154
by: Sigmathaar | last post by:
Hi, I'm need some advice about lists and vectors. I'm doing a program who needs to have sequential access of a non ordered unit of objects whose size decreases almost each time the sequence is...
3
2146
by: aurora | last post by:
This is an entry I just added to ASPN. It is a somewhat novel technique I have employed quite successfully in my code. I repost it here for more explosure and discussions. ...
1
2273
by: julian_m | last post by:
I'm just beggining to write some simple-small script which is gonna work as a mini chat. First aproach: File: comments.xml every time this file is accessed, I delete the first line (if number...
7
54235
by: LucasLondon | last post by:
Hi, I have the code below that I adapted to loop through each column of data (Columns A to GR) to perform an a calculation based on the data in rows 2 to 31 of each column and place the...
5
2909
by: =?Utf-8?B?R3VpbmVhcGln?= | last post by:
Hi, I just wrote a mini C# lab for myself, I think it may be useful for others, so I shared it on my blog. If you often need to write only serveral lines of code and don't want to waste time on...
0
7054
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7097
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
6993
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5353
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4794
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4493
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2993
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
567
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
193
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.