|
Because the syntax didn't allow me to write without converting to string! Can fix it removing the .toString(); if it is possible!!!
Or I need an other alternative code if possible? Thanks!
|
|
|
|
|
Well you neeed to figure it out based on what object type is held in that cell.
Veni, vidi, abiit domum
|
|
|
|
|
The type of object held in that cell(column) is integer or double.
Thanks!!!
|
|
|
|
|
So all you need to do is add them all together, right? You really need to think a bit more about exactly what you are trying to do here, and explain it in proper detail. Telling us that a column can hold an integer or real number is not particualrly useful, as it tells us nothing about what your actual problem is.
Veni, vidi, abiit domum
|
|
|
|
|
I have Tested the code to add up all double values in one column! And The Error is: java.lang.NullPointerException, Pointing to the the line of code: sum+=Double.parseDouble(tblviewTaxDetails.getValueAt(i,5).toString());
Please help modifying it!!! Thanks!!
|
|
|
|
|
Cyber12 wrote: The Error is: java.lang.NullPointerException Which means that you are tring to refer to an item by an invalid reference. You should try to break the offending statement into its constituent parts and then use your debugger to find out why you have a NULL pointer in there. In the above case something like:
Double dblValue = tblviewTaxDetails.getValueAt(i,5);
sum += dblValue;
Understanding what NullPointerException s are, what can cause them and how to avoid them, will make your life considerably easier.
Veni, vidi, abiit domum
|
|
|
|
|
Thanks!!! Problem Solved!!! It was because of the number of rows in the JTable!!!! It must be equal to the number of values to be summed up!!! My JTable initially had 100 rows, I tried it adjusting the number of rows equal to the number of records displayed in the JTable! It's now working properly! Thanks!
|
|
|
|
|
What will be the default value of indexes when i create
char[] ch = new char[50];
|
|
|
|
|
What indexes are you talking about?
Veni, vidi, abiit domum
|
|
|
|
|
such as index ch[5] ... i just want to know is null="" ???
|
|
|
|
|
What happens when you try it, or use your debugger to check?
Veni, vidi, abiit domum
|
|
|
|
|
|
i have to write junit testcases using annotation for spring application can anyone suggest link or tutorial to me.
|
|
|
|
|
|
that search even me also did.but i didnt get propely how to do with annotations
|
|
|
|
|
|
I have a form in which I have made File no field which hold the Integer value like 1-2-3-4 and so on.
I want that ,when I save a form which has file no 1 ,and then after when I want to save the next record it should remember the last file no and increment by 1.
I have not coded yet anything because I don't know if it is possible?
|
|
|
|
|
chdboy wrote: I don't know if it is possible? It definitely is possible. You just need to use a variable to hold the value, and use that to display in the field. Every time you save a file, increment the value and refresh the displayed field.
Veni, vidi, abiit domum
|
|
|
|
|
thanks for the Idea I'm working on it.
EDIT:
I managed to do what I wanted BUT...
It only happens till the application is open and I'm saving data one after one...as soon as I close to application and opens in again I have see the last file no and enter the next file no manually.
with this code
String filenostr = filenotxtfield.getText();
statement.setString(1,filenostr);
int fileno=Integer.parseInt(filenostr);
fileno++;
String convertno=String.valueOf(fileno);
filenotxtfield.setText(convertno);
statement.executeUpdate();
int rowsAffected = statement.executeUpdate();
if(rowsAffected > 0)
{
JOptionPane.showMessageDialog(null, "Data Inserted successfully!");
}
else
{
JOptionPane.showMessageDialog(null, "Data is not Inserted!", "Not successfully", JOptionPane.ERROR_MESSAGE);
}
statement.close();
con.close();
Addition to that I'm getting error on line
int rowsAffected = statement.executeUpdate();
ERROR:
com.microsoft.sqlserver.jdbc.SQLServerException: Violation of PRIMARY KEY constraint 'PK__Employer__6F09E6800F975522'. Cannot insert duplicate key in object 'dbo.Employer'.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:216)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1515)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPreparedStatement.java:404)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(SQLServerPreparedStatement.java:350)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:5696)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1715)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:180)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:155)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeUpdate(SQLServerPreparedStatement.java:314)
But as I see in my Management Studio that the data has been saved.but still getting this error ..why?
modified 22-Nov-13 1:08am.
|
|
|
|
|
I'm able to display the value after data is saved, but it is showing me wrong value with this code.
int fileno1=Integer.parseInt(Result.getString(2));
int increment = ++fileno1;
String convertno1=String.valueOf(increment);
filenotxtfield.setText(convertno1);
If 1 and 2 file no already exists after entering 3rd number manually and then save it ,it is showing me 2 not 4.?
|
|
|
|
|
That code looks fine as it stands, but you are not saving the updated count anywhere.
Veni, vidi, abiit domum
|
|
|
|
|
Do I have to save it in the database and then retrieve it?
int increment = ++fileno1;
I have to save increment in the database?
|
|
|
|
|
It depends on how long you need the value, but you have to save it somewhere. If you only need the value for a single execution of the program, then just keep it in memory. If you want to continue where you left off with another separate execution, then you need to kepp it somewhere permanent, database, property etc.
Veni, vidi, abiit domum
|
|
|
|
|
ok right now I have not made is permanent,but I think I will save it in the database so when the application loads it will still remember the last file no ...thanks for the Idea.
Right now I have done it with this code.
int fileno1=Integer.parseInt(Result.getString(2));
int increment = ++fileno1;
int increment2 = ++increment;
filenotxtfield.setText(Integer.toString(increment2));
I have used this code after inserting the data in the database.So now as you suggested I'm working on how to show the next file no upon application starts.
|
|
|
|
|
I'm not sure if you're aware of this. But what this code does is essentially:
int fileno1=Integer.parseInt(Result.getString(2));
fileno1 = fileno1 + 1;
int increment = fileno1;
increment = increment + 1;
int increment2 = increment;
filenotxtfield.setText(Integer.toString(increment2));
if you just want to increment the value of fileno1 (and don't need those variables increment and increment2) by 2:
int fileno1=Integer.parseInt(Result.getString(2));
fileno1 = fileno1 + 2;
filenotxtfield.setText(Integer.toString(fileno1));
|
|
|
|