javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Well for reading a file I use BufferedReader:

String fileName="C:/folder1/file.txt"
BufferedReader reader = new BufferedReader( new FileReader(fileName) );
String line = reader.readLine();
while(line!=null) {
   System.out.println(line);

    line = reader.readLine();
}

First you need to read the first line which happens outside the loop.
Then in order to enter the loop and continue, what you read should be not null. At the end of the loop after you have finished with all the calculations you read the next. Again you check to see if it is not null in order to continue. At the end of each loop you read the next line, so when you go at the begining you need to check if it is null or not in order to continue.
When you have reached the End Of the File the reader.readLine(); will return null so the while loop will exit.

Now after you have read the line here is an example on how to proceed

String line = "2 3";
String [] tokens = line.split(" ");
//tokens[0] has value "2"
//tokens[1] has value "3"

addPoints(Integer.parseInt(tokens[0]), Integer.parseInt(tokens[1]));

As for question about entering parameters, if you run the program like this:

java MainClass C:/folder1/file.txt

Then inside the main, the args array will have size 1 and the args[0] will have the input you gave:

public static void main(String[] args) {
		String file = args[0];
                System.out.println(file);
	}

Of course all the necessary checks should be made. Example:

public static void main(String[] args) {
    String …
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Well this is what I got with mixed numbers:

[1, 2, 3, 4]
[4, 3, 2, 1]
Enter the value you want to search for
4
The value you searched for is at index -5

It should have returned '3'.

After searching the API for collections
found that the method you are using :
int binarySearch(List<? extends Comparable<? super T>> list, T key)
requires a list that implements the "comparable" interface. so when I tried this I got an error: int where = Collections.binarySearch(Arrays.asList(a), searchValue); Because Arrays.asList(a) returns an Object list that doesn't implement the Comparable.
But there is another method you could use if it is not a limitation:
int binarySearch(List<? extends T> list,
T key,
Comparator<? super T> c)

Instead of implementing the Comparator, the API says that if you enter null: A null value indicates that the elements' natural ordering should be used. So it will use the comparator of the Integer class.
so try this:

Object[] a = mylist.toArray();
		Arrays.sort(a);
		System.out.println(Arrays.asList(a));
		//not working because mylist is not sorted in ascending order
		//must make sorted list the parameter for the Collections.binarySearch
		System.out.println(mylist);
		System.out.println("Enter the value you want to search for");
		int searchValue = scan.nextInt();


		//int where = Collections.binarySearch(mylist, searchValue);

		int where = Collections.binarySearch(Arrays.asList(a), searchValue, null);


		System.out.println("The value you searched for is at index " + where);
Grn Xtrm commented: Big help. Thanks. +1
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

why you say it doesn't work. I have run it like this:

Enter the number of values to be added to the list
4
Input the values
4
3
2
1
[1, 2, 3, 4]
[4, 3, 2, 1]

As you can see the array 'a' is sorted ([1, 2, 3, 4]) , whereas the 'myList' is not [4, 3, 2, 1].
what were you expecting?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

First of all this: if (buffer.equals(null)) is totaly wrong. Not because it won't compile but because
If buffer is null you cannot call any methods. You will get a NullPointerException


The best way to check if something is null is the simplest: if (buffer==null) For all the other cases use .equals()

Also as for your code I prefer this simple solution:

String buffer = br.readLine();
int i=0;
while (buffer!=null){
  buffer = buffer.trim();
  if  ( (buffer.length!=0) && (buffer.charAt(0)!='#') ) {
       
          StringTokenizer st = new StringTokenizer(buffer," ");
          token = st.countTokens();

             if (st.hasMoreTokens()) {
                if (i==source.length) break;

                source[i][0] = (st.nextToken());
                source[i][1] = (st.nextToken());     
                i++; 
            }
  }
  buffer = br.readLine();
}

With your way you have 2 loops (while and for) but you use only ONE. At the end of the for, you read the next line and you continue with the for, so the while is not needed. BUT since increase the 'i' index in the for and the coninue, the array 'source' will have some elements missing.
Example, you will have source[0] have some value but as you increase the 'i' when you go to put again value, the next time might be source[3]. So those that are between will have null value.

With the above way, after the while has finished the 'i' will hold the number of lines actually put in the array. If only 4 lines much the requirements you will have values for:
source[0], source[1], source[2], source[3] and the rest …

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

can you do a System.out.println of the values:
id and fullName before you set them at the lifeinsured object?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
VALUES ('" + id + "','" + fullName

I don't see a missing quote. Are you sure this is the code you tried to run?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The problem is where you create your query not where you read the value and call the set method:
Assuming this:

public void setId(String id) {
   this.id = id;
}

>>> query = . . . . + "'" + id +"', "

I think you forgot to add the single quote at the query.
Post the relevant code where you generate the query

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Yes, read it in as a String and print it out. ?

Actually what smsamrc is asking is to print at the console something like this:

To have 2 as base and 3 to be smaller and to the upper right corner of 2.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The first error is easy. You cannot compare String using this: "<". For Strings you need to use this function:

if (  txt_pay.getItem().compareTo(txt_amount.getItem())<0  )
{
   jOptionPane1.showMessageDialog(this, "please enter the right amount");
}

And when you do this:

if (txt_pay.getItem().isEmpty())

The method isEmpty() needs to return a boolean value.

Also in java the 'null' value is this null

if (txt_pay.getItem() == null) // 2 '=' symbols when comparing

Also use this '==' when comparing a String with a null value like above, but if you want to compare 2 Strings that have value use this:

if ( !txt_pay.getText().equals("")  )

Also this converts a String into a numer

String s1  = "22.22";
double d = Double.parseDouble(s1);

String s2  = "13";
int i = Integer.parseInt(s2);
jam7cacci commented: fantastic! he's a great help +3
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Here is a suggestion I wanted to give you from the start but after seeing your implementation I thought it would be better to follow your approach since you have already written code for it:

class SinglePolynimial {
  public int power = 0;
  public double factor = 0;

  public SinglePolynimial(double factor, int power) {
     this.power = power;
     this.factor = factor;
  }

  public SinglePolynimial() {
  }

  public void mult(SinglePolynimial single) {
      power = power + single.power;
      factor = factor * single.factor;
  }

 public static SinglePolynimial mult(SinglePolynimial a, SinglePolynimial b) {
      int power = a.power + b.power;
      double factor = a.factor * b.factor;
      return new SinglePolynimial(factor, power);
  }
}

3.1x^5:
new SinglePolynimial(3.1, 5);

So this polynimial: 3x^2 + 4x + 5
will be ONE Vector with elements SinglePolynimial objects, each elements for each part of the polynimial: 3x^2 + 4x + 5

So you will have 2 Vectors, multiply each element of one vector with each element of the other vector using the methods of the objects and store them somewhere, (maybe a third vector).

Then you can itereate the elements of the new vector, and those that have the same power, add them.
Or you can do the add in the same with the multiplication.
But be carefull to add only those that have the same power.
Maybe you can add these methods to the class as well:

public static SinglePolynimial add(SinglePolynimial a, SinglePolynimial b) {
      if (a.power!=b.power) {
          return …
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I didn't quite understood what you really want because I think it is very simple:

Vector v = new Vector();
v.add("4 2 5 3 6 0");

or

Vector v = new Vector();
v.add("4,2");
v.add("5,3");
v.add("6,0");

or insert them in any format you like

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Can't you use the Vector argument by reference ? :

Vector v = new Vector();
method(v);
System.out.println(v.get(0));

void method(Vector v) {
  v.add("1234");
}

Maybe it cannot be done since I don't know how JME really works or how you have written your code

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I don't know if this suggestion applies to your problem, but you can try this:

Have the class implement the Comparable interface:

public class ContactListLabel implements  Comparable<ContactListLabel > {

public int compareTo(ContactListLabel label) {
  return nameLabel.compareTo(label.getNameLabel());
}
}

When you get the Contacts from RMS and store them in ContactListLabel objects, can you put them in an array instead of a Vector?
If you can, you can use this: Arrays.sort(Object[] a) to do the sorting.
Or after you have the Vector with all the Contacts put them in an array and sort them with the above method.

Again, I have never used JME and I don't know if you can use this solution, but if sorting is your only problem then it is not very difficult to simplify your solution

----------------------------------------------------------------------------

Another thing you can do is sort them the moment you get them from RMS:

> get contact from RMS
> search the Vector with the objects using the nameLabel and find at which index it needs to be inserted
> do the insertion at the index found.

That way you don't need to call the sort method.

If the Vector has, for example, elements:
"a", "b", "d"

And you get the "c" you will search the Vector to find where the "c" needs to be inserted:
if ("c"<"d") put it where the "d" is, and the "d" will automatically …

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Try "right" clicking on the file and select "Properties". You will find the exact location and file name to use at your code

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You can have the variable be "global". Here are 2 examples:

class ClassA {
public int variableA = 0;

public ClassA() {

}

public void method() {
   variableA = 2;
}
}
class ClassB {
public ClassB() {

}

public void methodB() {
  ClassA clA = new ClassA();
  clA.method();

  System.out.println(clA.variableA ):
}
}

If you have a variable declared in a method you cannot access it from outside that method because it is out of scope. You need to declare it inside the class. If you declare it "private" you will need a "get" method in order to return its value.
Now if you want to access it from another class you will need of course to create an instance of the class: "ClassA" and call the method that changes its value.

But things are different when you declare it static:

class ClassA {
public static int variableA = 0;

public static void method() {
   variableA = 2;
}
}
class ClassB {
public ClassB() {

}

public void methodB() {
  ClassA.method();

  System.out.println(ClassA.variableA):
}
}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I don't believe there is a class that does what you want.

Also I checked the Time class and I don't believe it is what you want. It is used with sql and it represents time like saying now the time is:
"16:05"

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You might want to create your own class.

The classes Date and Time are used to store what the say: Date and Time.
You need to store duration. (duration of race)
You cannot say that a swimmer swimmed for 'Date' object time.

But you can say this:He started swimming at Date start = new Date() and finished at Date finish = new Date() And their difference is the time he made in milliseconds: long time = end.getTime() - start.getTime()

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You can loop backwards the arrays, take the elements and convert them into Strings and concatenate them. Then convert the Strings to numbers and multiply them.

String s;
loop i
  take element i
  convert it to String
  concatenate it to s variable
end loop
convert s to number
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
public void readtext(){
        Adult MyArray[] = new Adult[ 5 ];
        Adult memAd = new Adult (0,"","","","","");
        int counter = 0;
		
        memAd.setMemName(NameTextField.getText());
        memAd.setJoinDate(DateTextField.getText());
        memAd.setMobNum(MobNumTextField.getText());
        memAd.setHomePhNum(HomeNumTextField.getText());

        counter = counter + 1;
		MyArray[counter] = memAd;
    }

You define the array inside the method but it can't be viewed from outside. It is out of scope. The MyArray array cannot be used outside that method. You need to define it outside the method as a class attribute, and use it to the constructor of your table model

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Simple program to read ONE file:

BufferedReader reader = new BufferedReader(new FileReader("filename.txt"));

String line = reader.readLine();
while (line!=null) {
  // line read is not null
// do things with the line
...
..
.


// read the next line and go to the beginning of the while. If it is null
// you exit the while because the file is over

line = reader.readLine();
}

reader.close();

API for File: http://java.sun.com/javase/6/docs/api/java/io/File.html
You will find a method that returns all the contents of a folder. check which of these are files and read them.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The constructor must have the name of the class:

class MyTableModel {
  public MyTableModel() {

  }
}

Yes, this is because MemNum is a static variable (auto increment) , thinking about it I don't want the user to enter it but I do want it in the table so I will sort that out.

Even if the above is true, I believe that you still need to have the same number of columns. Since the methods getColumnCount, getColumnName will probably generate 4 columns, the values put in the cells will not be correct. Of course you could try this:

private String[] columnNames = {"Name", "Date","Mobile Number","Home Number"};

public Object getValueAt(int row, int col) {
        Adult memAd = data[row];
        switch (col) {
           case 0: return memAd.getMemName();
           case 1: return memAd.getJoinDate();
           case 2: return memAd.getMobNum();
           case 3: return memAd.getHomePhNum();

           case 4: return memAd.getMemStatus();
        }
		return memAd;
    }

but "memAd cannot be resolved"

That has nothing to do with the JTable part. You have to declare the array somewhere where it can be seen, when you try to use it

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

That is not a consructor:

public void myDataModel(Adult[] memAd ) { // pass in data array to constructor
	data = memAd;
    }

This is a constructor:

public MyTableModel(Adult[] memAd ) { // pass in data array to constructor
	data = memAd;
    }

I see that at the method: getValueAt you 5 options(col) 0-4 but in the array columnNames you have 4 elements.

Also I am not familiar with Jtables and Models, but since the call you have created IS a AbstractTableModel, maybe you can try this:

Adult [] adults = .......
//put values in the above array
 jTable1.setModel( new  MyTableModel(adults))

Check these links:
http://java.sun.com/javase/6/docs/api/javax/swing/table/AbstractTableModel.html

http://java.sun.com/javase/6/docs/api/javax/swing/table/TableModel.html

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

System.currentTimeMillis(); It returns the current time in milliseconds. So you can call this method before the java method you want to count and then call it again and get the difference

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Because you haven't converted correctly the code.
You put the line in the ArrayEntry[0] and the rest of its values are null.
You check the ArrayEntry[0] if it is "." which is not because it contains the entire line.

You don't need the array, the line's value is stored in the parameter. That parameter alone you need to work with.
And you stilled haven't check my suggestions about the String class. Why don't you take a look at it

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

This is how you declare methods:

public static int getRank(String line) {
  int rank;
......
  return rank;
}

And call it:

String [] name = new String[i]; //remember the "i" ?
int [] rank= new rank[i]; //remember the "i" ?
....
for(int counter=0;counter<i;counter++) {
 System.out.println(LineArray[counter]);
 
  rank[i] = getRank(LineArray[counter]);
 ...
}

The LineArray[counter] is a String that has the current line from the for-loop. It is that line that you enter as a parameter to the method in order to get the rank. Inside the method you will deal only with the argument, because it has the value that you pass it when you call the method:

The argument "line" has the value of the argument when you call it. When you call it like this: getRank(LineArray[counter]); "line" has the value of: "LineArray[counter]" . So inside the method you will deal only with local "line" variable of the method.

public static int getRank(String line) {
  int rank;
......
  return rank;
}

I have already told you which methods to use from the String class and how to use them

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I haven't used FileChooser much, but have you tried these methods:

setApproveButtonText(String approveButtonText)
Sets the text used in the ApproveButton in the FileChooserUI.

showDialog(Component parent, String approveButtonText)
Pops a custom file chooser dialog with a custom approve button.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

First of all loop through the existing array like you are already doing and try to "extract" the 3 values from each element. Write separate methods for that.After you are successful you can create 3 arrays and put these inside with each loop:

String [] name = new String[i]; //remember the "i" ?
....
for(int counter=0;counter<i;counter++) {
 System.out.println(LineArray[counter]);
 
  name[i] = getName(LineArray[counter]);
 ...
}

The getName(LineArray[counter]); will take as argument the element of the array and return the name. You will have other methods for the "sport" and the "rank".

The best way is to create an object "Athlete" with attributes name, rank, sport and have a method that takes as argument the element of the array and return that object. Then you will put that in an array of "Athlete" objects. If you are not familiar with that leave for now

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Why do you say that this didn't work:

while (!(lineRead.equals(null)) && (i<LineArray.length))
//lineRead !=null did not

If lineRead is null you will get an Exception.
Why this thing doesn't work and what problems do you have?

while ( (lineRead!=null) && (i<LineArray.length) ) {

}

Also the same applies to this:

finally {
....
   if ( read!=null) read.close();
....
}

By the way, this was smart:
while ( (lineRead!=null) && (i<LineArray.length) )

Now you will never exceed the length of the array. But I would like to suggest that at the for-loop to use the i as max index:

Instead of this: for(int counter=0;counter<LineArray.length;counter++) Use this:

for(int counter=0; counter<i; counter++)

Because if the file has less lines let's say 10, only the first 10 elements of the array will have values. The rest will be empty (null).
So you will need to loop only till you reach the number of lines that were inserted in the array, which is the "i" value.

Now that you have the array ready, use the suggestions in my previous post on how to use the "subString" and "indexOf" methods on order to get what you want

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Let me explain this code a little and then I will tell you your mistake:

BufferedReader reader = null;
try {
    reader = new BufferedReader(new FileReader("fileName"));
    String line = reader.readLine();
    while (line!=null) {
        System.out.println("The Line is: "+line);

        // do calculations with line

         line = reader.readLine();
    }
} catch (Exception e) {
} finally {
}

Read the first line: String line = reader.readLine(); Checks if the line is null or not. If it is not continue: while (line!=null) { Then inside the loop you do the calculations.

AT THE END OF THE LOOP you read the next line, and check if it is null or not: while (line!=null) { . If it is not null continue.

This code must not be altered. The LAST command of the while loop must be the readLine. Because after that you go to the top, check the line and continue with the loop only if it is not null. If you read the line in the while you must not do any more calculations, because you haven't checked the new line. You need to go to the top. That's why it is the last command. And it must always executed.

while (line!=null) {
        //ALL CALCULATIONS ARE DONE HERE WITH THE LINE        

         
         //YOU GET THE NEXT LINE ONLY HERE AND GO TO THE TOP TO CHECK IT
         line = reader.readLine();
    }

With this code:

while (line != null ){
                //System.out.println(test);
                if (test.equals("")){
                    test=read.readLine();
                }
                else{
                    line[i]=test;
					i++;
                    System.out.println(line[i]);
                }
			}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

That is not the code I gave you for reading a file.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Well, since you have copied that code directly to main, you need to add this as well:

finally {

    try {
       if (reader!=null) reader.close();
   } catch(Exception e) {
   }

}

I was expecting for you to put that code in a method that throws an IOException. But putting it in main might be enough for you now.

You got that error because the reader.close(); throws an Exception. But it is best to put it in the finally block in order to make sure that it is always executed.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I have never used arrays in Java, although I used them in Python but whatever u wrote up there i understand some of it because I have reading lots of blogs and online articles about java arrays.
and about the line problem my file is formatted in this way
1. JOHN CARTER in Sprint Race.

Then forget about the split method and check the String API for the methods:
indexOf
subString

Find the index Of the first '.' dot and take the number using the subString
Then find the index Of 'in' and use the subString to get the name and the sport

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
BufferedReader reader = null;
try {
    reader = new BufferedReader(new FileReader("fileName"));
    String line = reader.readLine();
    while (line!=null) {
        System.out.println("The Line is: "+line);

        // do calculations with line

         line = reader.readLine();
    }
} catch (Exception e) {

} finally {
  if (reader!=null) reader.close();
}

If you are unfamiliar with using arrays, I would suggest to concentrate on that first, before going to write the code for reading from the file. Once you have understood the arrays very well, you may proceed.
Also it is best to have your file formatted like this:

1;JOHN CARTER;Sprint Race
19;JOHN CARTER;Sprint Race

Because of the split method. Try to run this example:

String s = "1;JOHN CARTER;Sprint Race";
String [] array = s.split(";");
for (int i=0;i<array.length;i++) {
  System.out.println(array[i]);
}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Firstly gabec94 I would like to note a few things that I have observed while going through this thread. You are not taking any heed of the advice and help given to you and just want to stick to the method of doing something in the langauge that you have worked with in the past.

You are are right.
I have already given him an example on how to convert the String to int, so he can use his beloved modulus but he hasn't made any effort to use it.

Also the same example you gave him with the charAt(). But just because he hasn't used the language before, shouldn't stop him from thinking the solution you gave him. The method and the example was already given.

Did you run the examples and understood what they do?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You cannot use modulus to a String. You need to convert it to number:

String s="12345";
int i = Integer.parseInt(s);
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

First of all.
Whenever you get an error, always check the API of the class you are trying to use. I have never used the Scanner class but obviously you are trying to use a method that doesn't exist. So check the API for Scanner class so you can see which methods it has.

Second,
The String API tells you what arguments they take what they return, and what they do.

Also run this example:

String s="abcd";

for (int i=0;i<s.length;i++) {
  System.out.println( s.charAt(i) );
}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

What kind of error, and didn't you notice the methods:

subString, indexOf, or charAt.

at the String API?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I usually use javascript to manipulate the state and value of the input fields. Haven't combined it with tables.
But I would suggest to post the code you have for the table as well as the javascript code and describe what you are trying to accomplish. If I know it I will reply

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The "mainMenu" should be the id of the table.
Since you are using this: document.getElementById("mainMenu") It is quite obvious when you say "getElementById" that the argument should be the id of the element you are trying to take.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You must also close the connection and the RsultSets at the end, so better make some public methods that do that.
Also you need to apply these changes to other queries as well:

This: rs=stmt.executeQuery("select username from userinformation where username=name") Should be rs=stmt.executeQuery("select username from userinformation where username='" + name + "'") And any where else is needed

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Of course, now I see it. It is very simple. The executeQuery is supposed to return a ResultSet. You use that method when you are querying the database (select * from ...) and you expect to get back some rows.

But the query you have is an INSERT query. You are asking for the database to return you a ResultSet: rs1=stmt.executeQuery("insert into userinformation(username,password,dateofreg) values ('"+name+"','"+password+"','"+dateofreg+"')"); But the INSERT query doesn't return anything, it is simply inserting.

So use this method:

int executeUpdate(String sql)

Executes the given SQL statement, which may be an INSERT, UPDATE, or DELETE statement or an SQL statement that returns nothing, such as an SQL DDL statement.

The int that returns is the number of rows affected. In your case will return the number of rows inserted (1)

Also next time you should check the API of the classes you are using:
Statement

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Try changing this line:

rs1=stmt.executeQuery("insert into userinformation(username,password,dateofreg) values(username,password,dateofreg)");

To this:

rs1=stmt.executeQuery("insert into userinformation(username,password,dateofreg) values ('"+username+"','"+password+"','"+dateofreg+"')");

Also the exception tells you at which lines you got the error. It would be better if you point out to us which lines are that, because we cannot just count 51 lines, especially when you post 2 classes at the same time

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You have 2 while loops one inside the other that do exactly the same thing in the opposite. There are much better codes than that:

boolean done = false;
while (!done) {

// and now k2k's code

enter input

    if (answer.equals("yes"))
    {
        do whatever calculations you want to do
    }
    else if (answer.equals("no"))
    {
        done=true;
    }
    else
    {
        System.out.println("Invalid option");
    }
}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
for (String s : list)
    System.out.println(s);

The idea is to learn about Lists, not to learn the different ways to iterate. I doubt that the above example would have helped in understanding how to add and get elements from lists.

There's no need to write one in C++, either. #include <list>

That I liked.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Check the API for ArrayList. It is the most commonly used

ArrayList list = new ArrayList();

list.add("asd");
list.add("fgh");
list.add("erty");

for (int i=0;i<list.size();i++) {
  String s = (String)list.get(i);
  System.out.println(s);
}

Or if you use generics (after java 1.5)

ArrayList<String> list = new ArrayList<String>(); //here you define what kind of objects you will put inside the list

list.add("asd");
list.add("fgh");
list.add("erty");

for (int i=0;i<list.size();i++) {
  String s = list.get(i); //you do not need to cast it to String like the previous example because of the way you defined the list above
  System.out.println(s);
}

Check the LinkedList in case it has methods that interest you

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

is there any book from which i can learn net beans

Try the tutorials of the net beans site.

And net beans is an IDE that helps you organize your projects. Shouldn't you been learning java?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Peter is right. If you don't want the message to printed at the console, don't call that method.

And as I asked in my post:

Where do want it to be displayed?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Where do want it to be displayed because I don't think that it can be done.

I would suggest you look at the API for
PrintStream

Because the System.out is type of PrintStream.

This will behave exactly like the System.out.println

PrintStream print = new PrintStream(System.out);
        print.println("aaaaa");
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I told you to write a main method in which you will call your other methods. You wrote this:

public class Main {
public class McBrideCR1{

The above doesn't mean anything. Surely this is not the first program you wrote. Check your notes. Writing a main method is the first thing you learn.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You need to write a main method in which you will execute the code you wrote. Right now you have only a class with methods. You need to call these methods inside the main