javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

visittable.getSelectedRow() visittable.getSelectedColumn()
When you select the row, the column get unselected. When you select the column the row gets unselected.
The api says that if a row or a column is not selected, they return -1, as the exception says.

About the insert, try printing the values you are passing and run the query directly to the database and see what happens.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You cannot write to note pad because notepad is an editor not a file. You need to write to a file. If you want to read that file using notepad then the file shoudend with .txt :

File file = new File("C:/path/fileName.txt");

I usually use BufferedWriter:

File file = new File("C:/path/fileName.txt");
BufferedWriter wr = new BufferedWriter(new FileWriter(file));

wr.write("Sometxt");
wr.newLine();
...
...

wr.close();

You will need to put the above inside a try - catch block.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

At your insert statement what values do you pass to each '?'. Are those values mapped correct with the database?

Also, you wrote the delete query. Meaning that you should know that it takes as argument the ID not the row number. You need to think how to get the ID of the selected row

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Have you tried printing the query to see what do you run.

About the delete method:
I will repeat myself once again. Read the JTable API. Are you sure that the getSelectedRow is what you need to pass as argument? What your query takes as argument and what the getSelectedRow returns.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I had a problem at work which I solved, but that raised me another question.
I wanted to export a page to excel, so I used this:

response.setContentType("application/vnd.ms-excel;charset=iso-8859-7");

It worked but while I was searching for an answer I found 3 possible content types for the excel:

> application/vnd.ms-excel
> application/x-msexcel
> application/ms-excel

As well as this: http://stason.org/TULARC/business/spreadsheets/10-19-What-is-the-correct-registered-MIME-Content-Type-for.html

What is the correct, registered MIME Content-Type for Excel files?

application/vnd.ms-excel

see http://www.isi.edu/in-notes/iana/assignments/media-types/application/vnd.ms-excel

so don't use any of these:
application/ms-excel
application/msexcel
application/excel
application/x-ms-excel
application/x-msexcel
application/x-excel
application/octet-stream

QUESTION:
Why only this: application/vnd.ms-excel is correct and those are not:
> application/x-msexcel
> application/ms-excel

kvprajapati commented: Great! +6
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The reason we assumed that you didn't know what you were doing is because you tried to find a way to call a main method:

public static void main(String [] args)

From a jsp. After seeing that most people assumed that have never written a jsp in your life!

But apparently you understood on your own, that writing lots of java code inside jsp is not a good idea, otherwise you wouldn't have tried to call separate methods (the main method) that had the logic inside it.

But in your second post you insisted in doing things your way instead of asking why you shouldn't do that. That is why most people didn't bother to explain since you didn't gave the impression that you were ready to listen:

I dont want to use servlets I want to work java inside jsp with html. that's the way I chose that's the way my web app program is working completly and flawlessly. okay I will call methods I got it. but I disregard the first advice and thxx

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

It is true that you can put java code inside jsp and it would work. It is not a problem if you have the minimum code (very few lines).

But you cannot put entire logic inside the jsp. All the logic needs to be done outside the jsp and inside the jsp you will simply print the results.

This is the comment I read in a book about java code inside jsp:
"Just because having java code inside jsp works, doesn't mean it is correct. With your logic someone might go and write the entire web application in assembly and it would work. That doesn't make it correct nor efficient."

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

That is how it's done. Also at your insert query. Does that table have only one column? You might get errors on that query if the table PatientTable has more columns.


Also about how to call them.

I did this but how could I call this in the buttons' actionPerformed methods?

I am sorry to tell you this, but you don't know how to call a method, and you are trying to create a gui that connects to the database?
No wonder that you couldn't understand anything I was telling you.
I am not saying this to put you down. It's the truth. Everybody would agree with me.
Calling a method is the most basic thing. You have written all this code and you don't know that? That proves you shouldn't be doing this.

Stop what you are doing and start over. Learn how to create objects instantiate them, use their methods. Try small exercises.

Given the amount of information you received it should have been a piece of cake to finish this. You have been given anything you need to finish this. All the advices and all the code that you couldn't find by yourself.
Now if you can't do this, it would be because you haven't studied what is needed.

Given your last question made me doubt that you even understand what the code you have written does or that you understood the code I gave you. There …

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I know that classes need to be inside main but there's no main here that's why I'm trying to call it from there.

That statement alone proves that you must stop right now working with JSPs. How much experience do you have with core java? Do you have any books about JSPs or are you just going blind?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

If you don't know sql you should have said that. You can search the web to find the syntax of the delete command. Then when you select the row use the JTable API to get the values of the row. You should have a primary key that you can use at the where clause. That needs to be taken from the JTable.

For the rest, I told you were and how to call it

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

What errors do you get?

Did you look at the API for the JTable to see what the getSeletectedRow does?

Why aren't you closing the Connection, Statement? How many times do I have to tell you that?

I already told you that you need to call a query to delete the row form the database as well. Didn't you read that?

Why aren't you using separate methods for the database operations. Do you find it easier to repeat code every time you want to insert or delete something:

public void delete(int id) throws SQLException {
   // commands
}

All the Connections, ... will be declared in that method.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

then have that link point to the same page and pass through the link your parameters.

<a href="samePage.jsp?param1=aaaa&param2=bbbbb">
</a>

Get those parameters at the beginning of the code and check if they are not null. If they are null means that the pages has just been load and you shouldn't search the DB. I they are not null it means that the page was loaded by clicking the link and you should use those parameters:

String param1 = request.getParameter("param1");
String param2 = request.getParameter("param2");

String dataToDisplay="";

if ((param1!=null)&&(param2!=null)) {
    // read from DB
    // DON'T OPEN THE CONNECTION HERE OR PERFORM ANY OPERATION REGARDING THE DB.
   // CREATE SEPARATE METHODS IN ANOTHER CLASS THAT DO THAT AND CALL THEM
    dataToDisplay = DBClass.readData(....);
}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

i have changed the names of the classes with capital letter and not to be in plural.
Account was inheriting customer because iam tring to have different accounts for invidual customers and for companies. There are (as it says in the assignment) different rates and calculations for different types of customers.

Then customers should have an attribute: rateType.
Also when Account extended Customer is like saying that Account is a Customer, whish is not.

The assignment says:

All accounts have customer,
balance and interest rate

So the Account class would be like this:

public class Account {
  private Custome cust = null;
  private double rate = 0.0;
  private double balance = 0.0;

// Constructor and get/set methods
}

Then, as the assignment says, you will have Deposit, Loan, Mortgage classes that extends Account and each one of them will have the attributes described at the assignment.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

And the code you used?
Also at which line do you get the exception. go there and see what is null

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

And to continue the suggestions, the Account class could look like this:

public abstract class Account {
  private Custome cust = null;
  private double rate = 0.0;
  private double balance = 0.0;
}

You can implement any methods you want (get/set). It doesn't matter that it is abstract. Create any methods you want.

And:

public class Deposit extends Account {
}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

It appears that up until now I am the only one that voted NET Beans. Also at work we use eclipse, but I prefer Net Beans at home.

Also the IDE that I hate the most is JDeveloper.

peter_budo commented: JDeveloper is crap indeed +12
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I understand where you are coming from.
Just frustating, I haven't used the () on the previous code . that what confused me. You are lot's of help, just be a little gentle, it's my first week with java.

I have lot's of other question and do not want to burn bridges.

In our previous posts we were simply urging you to look back at that previous post.
Also if you have anymore questions fell free to create a new thread and post them. Don't forget the code. You don't want to give the wrong impression.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Thanks anyways

The solution is explained here. The example doesn't have a '-' operator but that is the idea of learning. Don't expect anywhere to find the exact code that you will need. You will find similar code, understand how it works and apply that behaviour to your needs.
Imagine what would have happened if we have told you to read the API

First of all use capital S:
System....

Second you do this:

system.out.println("The sum is:      "[B]+[/B]num1 + num2 + num3);

- You forgot the '+'
- Things are executed from right to left:

"The sum is: "+num1 + num2 + num3 -->
"The sum is: "+13 + 27+ 14
Meaning that first this will calculate:
"the sum is: "+13, which will create the String:
"The sum is 13".
Then this:
"The sum is 13" + 27, which will create the String:
"The sum is 1327".
Then this:
"The sum is 1327" + 14, which will create the String:
"The sum is 132714".

Whenever you "add" something with a String is turned into a String as well.


> num1=5
> num2=6

This: "A= "+num1 will return
>A= 5
This: "A= "+num1+num2 will return
>A= 56
This: "A= "+(num1+num2) will return
>A= 11

You should do this:

System.out.println("The sum is: " + (num1 + num2 + num3) );
System.out.println("The product: " + (num1 * num2 * num3) );

Or better, use …

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

What didn't you understand form post #8 of this thread:
http://www.daniweb.com/forums/thread255237.html

Also what errors do you get from the code you posted?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Hi javaAddict: I hadn't realised that you were already dealing with mseck's problem. (And, once again, I apologise for my "senior moment" with the + , even worse now I've read the previous thread!).
I gonna bow out now, before I make a bigger fool of myself.

That was a different thread. But that is irrelevant. Anyone can post their opinions in any thread. It is not like that once some one posts an idea no one is allowed to continue with the help.
My point was that the OP already made the same question in another thread and got an answer.


To mseck:
It seems to me that you didn't add the parenthesis I told you in one of my answers at the other thread. What is the point in asking questions if you don't follow the answers?
Add those and I believe that the errors would be fixed.
If not post again the new code with the errors

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

For some reason when i try to compile it, i still get an error pointing at the operator

In your other thread, I already told you how to correct all your mistakes. I explained much in detail and told you what to change and correct, but you INSIST in writing the same things, as if you didn't pay any attention whatsoever to what I said.
You already have the solution in your other post but you chose to ignore it.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Like I said, read the explanation I gave you at post #8
And you forgot another '+' at the line where you print the product

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Lab1App.java:14: ')' expected
System.out.println("The product: "num1*num2*num3);
^
Lab1App.java:14: illegal start of expression
System.out.println("The product: "num1*num2*num3);
^
Lab1App.java:14: ';' expected
System.out.println("The product: "num1*num2*num3);
^
Lab1App.java:14: not a statement
System.out.println("The product: "num1*num2*num3);
^
Lab1App.java:14: ';' expected
System.out.println("The product: "num1*num2*num3);
^

In my previous post, I ,mentioned that you forgot the '+' symbol and some quotes

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

For some reason i still get error
Could it be the way i installed JDK 6.18?

Check your quotes.
Then post your new code, with what error messaged you get.

For future reference, first open AND close a double quote, and then start writing inside.
the same goes for opening brackets and parenthesis

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

First of all use capital S:
System....

Second you do this:

system.out.println("The sum is:      "[B]+[/B]num1 + num2 + num3);

- You forgot the '+'
- Things are executed from right to left:

"The sum is: "+num1 + num2 + num3 -->
"The sum is: "+13 + 27+ 14
Meaning that first this will calculate:
"the sum is: "+13, which will create the String:
"The sum is 13".
Then this:
"The sum is 13" + 27, which will create the String:
"The sum is 1327".
Then this:
"The sum is 1327" + 14, which will create the String:
"The sum is 132714".

Whenever you "add" something with a String is turned into a String as well.


> num1=5
> num2=6

This: "A= "+num1 will return
>A= 5
This: "A= "+num1+num2 will return
>A= 56
This: "A= "+(num1+num2) will return
>A= 11

You should do this:

System.out.println("The sum is: " + (num1 + num2 + num3) );
System.out.println("The product: " + (num1 * num2 * num3) );

Or better, use the code from my first post.

Also without posting code, there was no way to help you. the only thing we could do is give you the complete code, which is unacceptable here.
Now you got the chance to learn something as well.

Also check your "" quotes at the System.out :

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Yeah I read some
here is for the delete button what I've done, but the prob is it removes the row from the Jtable but not from the datadase table.

Because you need to run a query to do that. And try to put it in a separate method, in a separate class that takes only arguments.


At the save row, what do you want to do? Because there are methods that can make the cells of the table editable, so you can change their values.
And then, when you click "Save", just take the selected Row, use the API to take the values of the cell and call a query at the database

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

First of all, it is OK to have multiple tags with the same name, but not the same id.
I suggest to change the id of those check boxes. With that way you can use DOM/javascript to modify their state.
Check the javascript and DOM tutorials here:
http://www.w3schools.com/default.asp

Also when you have many inputs with the same name, you can use the

// name="ckbox"
String [] s = request.getParameterValues("ckbox")

That will return all the values of your "checked" check boxes inside an array.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Good Morning !

Who said it was my homework?
I am trying to lean it on my own, I've tried to do it but keep on getting error.

i would appreciate, if i could get directed the right direction.


thank you

Then post your code, and don't tell me that you couldn't do this:

int sum = num1+num2+num3;
int prod = num1*num2*num3;

And if you say that you already know that, you asked:

How to i write a java application that inouts 3 different integers from the keyboard and prints the outpout as in the following :

Output

the 3 different integers are: 13, 27, 14.
the sum is 54.
The product is 4914
completed.

You don't mention anywhere where is your problem. From your question you make it sound that you want the whole thing done.

Post what you have done so far and with what are you having problems.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Hello musthafa!
Please help on this , I didn't get what JavaAddict meant.
Can you materialize the words by some snippets?
Thank you!

Did you look at the JTable API? There is a constructor that takes as argument TableModel. That is how you will instantiate your JTable. You already have the DefaultTableModel. Just use this as argument
And read their APIs. All the methods you need are right there.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

There are tutorials here: http://www.w3schools.com/default.asp on how to create tables and links.
You can also place a link inside a table:

<td>
<a href="some_link.jsp">some text</a>
</td>

Now if you don't know how to read data from the database, that is an entirely different thing, and you need to be more specific with your question.
As far as writing java code inside a jsp, there are a lot of things that cannot be mentioned here so you'd better read a book or something and come back with some specific questions

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You need to pass at the constructor of the JTable as parameter the DefaultTableModel. Check the API of JTable.
Then use the methods of DefaultTableModel to add, remove, or update the rows. Check the API of DefaultTableModel.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

If you want more than 1 command to be executed "under" the if, you will need brackets:

if (number1 < number2)
..
..
..
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

What do you expect to get?
Try to put some System.out.println outside and inside the loop and see if it goes inside. Maybe it never goes inside the loop becuase the command: java -classpath /home/muzammil/apache-tomcat-6.0.18/work/Catalina/localhost/remote_compile/ filen[0] doesn't return anything. Try to print hte filen[0] and run it at a command prompt.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

This has more chances of working. Compare the changes I made with your own. What do you get as ouput:

try
                  {
   
       String line;
        // String path="/home/muzammil/apache-tomcat-6.0.18/work/Catalina/localhost/remote_compile/"+filen[0];
      Process p = Runtime.getRuntime().exec
       ("java  -classpath /home/muzammil/apache-tomcat-6.0.18/work/Catalina/localhost/remote_compile/" +filen[0]);
     BufferedReader input =
       new BufferedReader
         (new InputStreamReader(p.getInputStream()));
     line=input.readLine();
out.println("<html>");
    out.println("<body>");
     while (line  != null) 
     {
       
    out.println("<br/>Output is:" +line  );
[B]line=input.readLine();[/B]
    }
input.close();
    out.println("</body></html>");
                    }
      catch (Exception err)
      {
     err.printStackTrace();
    }

Also these need to be outside the loop: the <html> and <body> tags should be printed only once.

Also you only call the readline only once. Meaning that you will keep printing the same line and the loop will never end. It will run indefent.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

So howd you do it cause I have the same homework ?

Follow the instructions from the replies that he got. Meaning start a new thread with what you have done so far, and we will continue from there and help.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

In your first code you were printing this:

line=input.readLine();
out.println("Output is:" +line  );

That should work. Have you tried it?


At the second code you are printing the object: p.getInputStream() . That is an InputStream object. It doesn't have any "printable" values.
It is not like you have a String object and you can print its value. When you call this: out.println(p.getInputStream()) with an object as argument, the toString method of the object is called.
It is like doing this: out.println(p.getInputStream().toString()) If you look at the API that object doesn't override the toString method from its super class: Object.toString(). That is why you get that, in comparison with this:
String.toString()

You need to use the BufferedReader to print each line.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

First of all why are you calling out.close ? And especially inside the while. What needs closing is the BufferedReader input, outside the while. You close it once you are done reading. If you close it inside the while, the next loop will execute and try to read the next line, from a closed BufferedReader.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

It is better to get the text from the JTextField and add it directly to the JComboBox using the add method of the JComboBox class.
I order to get use the getSelectedItem method of the JComboBox class. It returns an object, so you will need to cast it to a String. Of course for this to work, all the items of the Combo Box need to be of type String.

Just in case, you used an other way to do it, and this one is more helpful.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Of course you get an error, since the Chars is an array of Game objects and you are trying to pass a String: "".
In the method you are doing:
Chars = new Game(nm, rc,typ, jc,wep)

Do the same, only this time pass empty Strings.

Also it is better to use the Vector class instead of an array. Just remember to override the equals method in the Game class

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
String[] hgfjhg = StudentClass.students;
studentNameList = new JComboBox(hgfjhg);

The "students" array in the StudentClass class is declared:

public static String [] students;

It is null!. That is why it is not working. You are giving values to this array inside the constructor. Do you call the constructor?

The above should fix your problem, but the entire logic is wrong.
Keep the StudentClass the way it is and remove the static array.
For that you will need a StudentClass array:

StudentClass [] lotsOfStudents = new StudentClass[5];

But since I assume that you will need to add and remove students better use this:

Vector<StudentClass> listOfStudents = new Vector<StudentClass>();

The above should be declared either as a global variable in the BHSSDatabasePanel panel. Or create a separate class with that as private and with public methods to add and remove.

For the above to work you will need:
> To override the equals method in the StudentClass. (in order for some useful methods of the Vector class to work correct)
> To override the toString method in the StudentClass. Have it return whatever you want. When you will add a StudentClass instance object to the JComboBox, what the toString method of the StudentClass returns, is what will be displayed

Look at the API of the java.util.Vector class and JComboBox class.

The equals and toString methods are inherited by the Object class.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

hai..pwedi nyo b akong bgyan ng isang code about selection sort....thanks

Start a new thread and write proper english

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

thanks alot =) how if i wanna compare not equals to? ( != )

equals is a boolean expression:

if (![B]s1.equals(s2)[/B]) {

}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Use the equals method to compare Strings:

temp2.equals("/")
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Hello All,

I'm trying to force my users to close a popup window before they can return to the Parent window. I more or less want to "lock" the parent window and force the user to fill in the info on the popup and hit submit, which in turn will close the popup and then allow the user to continue working on the parent window.

Are you saying that when the popup opens, the user shouldn't be able to select the parent window?
If yes try this:
jqModal/
You will also need to download jQuery.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

GIVEN: patient,doctor,descriptions of doctor,does+medicines,visits,invoice,invoice detail.
1-recognize the given in a table
2-desighn the organized table
3-determine the primary and secondary key
4-describe

We are not a service that does people's homework for free

Salem commented: Well said +19
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Have you looked the API for JFileChooser?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

So that reason for the exception does not hold.However typing in Y several will make an exception

That is what I said:

If the user continues to enter "Y" the program will run out of memory and crash.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

yes thanks .better to use while . otherwise the code is fine , i believe.

Actually you will get an Exception, because your method keeps calling itself. If the user continues to enter "Y" the program will run out of memory and crash.
Just because it will happen after many attempts of inserting "Y" it's not a excuse for writing unstable code

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

No, with your way, he will get an OutOfMemoryException:

private void getStudentsByGrade() {
  if (...) {
     getStudentsByGrade();
  } 
}

After pressing yes too many times.

Couldn't you just use this in a single method:

while (ans.equalsIgnoreCase("Y")) {

}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

To append at the end of the file, use:

BufferedWriter wr = new BufferedWriter(new FileWriter("filename", [B]true[/B]));

Don't forget to check the API for the above classes.

To write in between you will have to use RandomAccessFile but when I tried that, it overrides what is written at the place you are trying to write.
Usually, you can read the entire file in a Vector (each element would be a line of the file). Then add the line you want at the place you want in the vector and write the file again