473,441 Members | 1,514 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,441 software developers and data experts.

i m unable to solve this problem in netbeans:

bansari
20
Get the operation to be done from the command line in the following format:
D for Delete
U for update
I for Insert
For delete operations get the userid from the command line and delete the record.
For the update and insert operations get the following information from the command line and insert the record.
Name:
Birth date:
SSC Percentage:
Fees:
Last accessed time:
Decide on the format best suited for input.




I m new to java and also to netbeans.i know ow to connect but i dnt know how to get to many command line arguments..We can give it in project property..but how can i compare that value of command line ::



i m getting no error but not output.

Expand|Select|Wrap|Line Numbers
  1. package assign22;
  2.  
  3. import java.sql.*;
  4.  
  5.  
  6. public class DataOperation {
  7.  
  8.     public static Connection connection = null;
  9.     public static Statement stmt = null;
  10.     public static ResultSet rs = null;
  11.  
  12.     public static void main(String[] argv) throws Exception {
  13.         String inputCh = argv[0];
  14.         String id = argv[1];
  15.          String url="jdbc:postgresql:postgres";
  16.  
  17.         String driver = "org.postgresql.Driver";
  18.         String user = "postgres";
  19.         String pass = "password";
  20.         String query = "select * from tbluser";
  21.  
  22.         try {
  23.  
  24.             Class.forName("org.postgresql.Driver");
  25.             System.out.println("hi1");
  26.             connection = DriverManager.getConnection("jdbc:postgresql:postgres", "postgres", "password");
  27.             System.out.println("Connection Successful");
  28.             stmt = connection.createStatement();
  29.  
  30.             String del = "delete * from tbluser where userid=" + id;
  31.  
  32.  
  33.             if (inputCh.equalsIgnoreCase("Delete"))  //i also tried to use equals,startsWith methods but failed
  34.                 //String del="delete * from tbluser where userid=" + id;
  35.  
  36.                 stmt.executeUpdate(del);
  37.  
  38.                 System.out.println("Deleted one Row Successfully");
  39.  
  40.             }
  41.             else
  42.             {
  43.                 System.out.println("There is some mistake");
  44.             }
  45.         } 
  46.  
  47.         }//end of try */ catch (Exception e) {
  48.  
  49.             e.getMessage();
  50.         }//end of catch
  51.  
  52.  
  53.     }//end of main
  54. }//end of class
  55.  

i m giving commandline arguments: Delete 1 //as userid

please help me.
Jul 26 '10 #1

✓ answered by chaarmann

@bansari
But classs.forName throws a ClassNotFoundException if the class will not be found (because you forgot to copy to project library):
This exception then would be caught in your catch(Exception e) statement. There you only call "e.getMessage()". That means, you got an error, but you didn't print out anything in this case.
(I would have printed a meaningful message instead, along with the exception, like System.out.println("deletion threw exception" + e).
So that was confusing. But maybe you meant "no error was printed" instead of "I got no error".

So my advice for the future:
Don't make an empty catch()-block or do some invisible logic there.
Always print out the exception in a catch()-block or rethrow it.

That means, if you only fixed the ClassNotFoundException, your code still has a bug. That the exception happened, this is not the bug and can happen anytime again (maybe someone else deletes it from the project library by accident and then searches like hell why it doesn't work anymore!) The problem is how your code deals with errors. Your code should be stable and not error-prone. Only if you fixed the catch()-block, you really fixed the problem. An if you are very nice to your fellow programmers which use or alter your code in future, you should print out a meaningful message, like "Please add the class ... to the project library". You already had big problems finding the error cause in your own code, so how big problems would someone have that has not written the code and must parse through thousands of unknown lines without a hint?

4 1986
chaarmann
785 Expert 512MB
i m getting no error but not output.
That's impossible. At least you should get the output "Hil" (whatever that means that you print out here). If not, then you should get an error.
That means either it passes line 25 or it crashes before.
And it's not the try-catch-statement where it can crash, it also can crash before: at line 14, where you access the 2nd array element in an act of suicide (that means without checking first, if the element really exists - maybe you didn't pass an argument ). But even then you should get "array index out of bounds" message right away at the command line!

Are you sure you are really executing the current program? Maybe you forgot to compile and it's executing a previous version, or you are in the wrong directory, or whatever...
Jul 27 '10 #2
bansari
20
@chaarmann
hi...i was doing small mistake that was ...i didn't copied the jar file of postgreSQL to this project's library..it was not getting driver which is in line 24.

Thank u.
Jul 27 '10 #3
chaarmann
785 Expert 512MB
@bansari
But classs.forName throws a ClassNotFoundException if the class will not be found (because you forgot to copy to project library):
This exception then would be caught in your catch(Exception e) statement. There you only call "e.getMessage()". That means, you got an error, but you didn't print out anything in this case.
(I would have printed a meaningful message instead, along with the exception, like System.out.println("deletion threw exception" + e).
So that was confusing. But maybe you meant "no error was printed" instead of "I got no error".

So my advice for the future:
Don't make an empty catch()-block or do some invisible logic there.
Always print out the exception in a catch()-block or rethrow it.

That means, if you only fixed the ClassNotFoundException, your code still has a bug. That the exception happened, this is not the bug and can happen anytime again (maybe someone else deletes it from the project library by accident and then searches like hell why it doesn't work anymore!) The problem is how your code deals with errors. Your code should be stable and not error-prone. Only if you fixed the catch()-block, you really fixed the problem. An if you are very nice to your fellow programmers which use or alter your code in future, you should print out a meaningful message, like "Please add the class ... to the project library". You already had big problems finding the error cause in your own code, so how big problems would someone have that has not written the code and must parse through thousands of unknown lines without a hint?
Jul 30 '10 #4
bansari
20
Thank you for suggesting me right path.It will be beneficial for me.It is good that expert person helps to novice too.
Jul 31 '10 #5

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

Similar topics

6
by: wonder | last post by:
Hi, The CRM application said that need to add an option "REGISTER_GLOBALS=On" to the php.ini file, so I did what it told. But I still can't get rid off the following error: The PHP variable...
6
by: Federico | last post by:
Hi, this is what I can do: - Create new solutions using VS.Net ASP.Net - Save the solutions, build the solution, view in browser with the solution still open. But, once I close the solution, I...
0
by: Jitesh | last post by:
I am facing a problem in webservice, I want to know what will be the exact procedure to solve the problem............. What I want to do............ I have a table named order in SQL Server....
5
by: Suresh | last post by:
Hi Guys I have Db2 server installed on remote server. i am connecting to that remote server by using VPN. I want to connect that remote DB2 server instance using my local machine DB2...
1
by: gkellymail | last post by:
I currently have a class with 29 data adapters and I will probably add a few more as time goes on. When I was testing earlier, i had 28 of them pointing to one connection and 1 pointing to a...
17
by: khajeddin | last post by:
the problem is: Create a class HugeInteger which use 40-element array of digits to store integers as larg as 40 digits each.Provide methods input, output, add, subtract how to add to arrays ?
6
by: joseph2000 | last post by:
Hi, I'd like to ask you for some ideas how to solve problem I currently have. The problem is as follows: we have a component which is integrated with w Windows Explorer. From time to time we...
5
by: rsingh | last post by:
HI guies can u help me to solve this problem. Write a program that prints a table of the binary equivalents of the decimal numbers in the range 1 through 256.
1
by: cooklooks | last post by:
http://www.videoriporter.hu/vr/fs?content=/vr/player/1320/date/count
3
by: vagandhi | last post by:
Hello friends, I am having problem while running below program. If anyone can help me.... // create class car #include<conio.h> #include<iostream.h> #include<stdio.h> // class declaration
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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
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,...
0
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
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
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.