javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Hi! Can sum1 plz help?!!!
here is the prob I'm having
SQLException: [Microsoft][ODBC Microsoft Access Driver] Too few parameters.

First of all Next Time start a new Thread.

My first guess would be that the table PatientTable has more columns than the ones you have at your INSERT query. Personally I always use this syntax:

INSERT into PatientTable (col1, col2, ..) values ('a', 'b', ...);

In that way you know what value goes where and you can omit some columns. I think that with your coding all the columns of the table need to have a value at the "insert" query, but with my way the table can have 10 columns (for example) and you can insert a new row by giving only value to one of the columns. Of course the columns that you leave empty must not have any NOT NULL constraints.

INSERT into PatientTable (col1, col2, col3) values ('a', 'b', 'c');

INSERT into PatientTable (col1) values ('a');

Of course knowing the structure of your table would help

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You just need:

name=null;

and garbage collector will do the rest.

Can you be more specific on that? What do you mean? Can you post some more code?
What is it supposed to be set to null?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

thats good to hear, i can probably guess why it change it is possible that when you uninstalled mozilla your settings change. thats probably one of the many reasons why that happen.

Actually I was having the error before I unistalled. All of the sudden it stopped working. That is why I unistalled in the first place.
You might say that the settings changed when a new version of firefox was installed, but my laptop continued working fine, and none of my friends had that problem

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

please try this clear you cache and cookies offline. temp disable your firewall. try to browse and check if the issue still exist. uninstall and reinstall your browser this time temp disable anti-virus and firewall and try to browse.

keep us posted hope that helps.

I have checked the firewall of my antivirus. For some strange reason, even though I could use the mozila with no problems, the settings looked changed.
In details: I opend my Anitvirus and went at the tab that said firewall. I clicked at the setting and it had several programs and how these programs should connect to the internet.
I saw that the settings of the IExplorer were diferent than the settings of the Mozila. Since I could connect to the internet using explorer, I changed the settings of the Mozila to be the same as the Explorer and I could use Mozila again

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Respected Sir,
Thank you for providing me solution. can you tell me how to
open connections or execute queries in JSPs. Which are the separate methods and classes that do that and call them from inside the jsp.

You will write the methods that open the connection and execute queries. Those methods will have the code that you are using now, but instead of having the code inside the jsp, you have it in seperate methods and classes that you will createa and call these methods from your query

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

My query is .
I want java code to convert RGB image (jpg) into grayscale then
i want to convert pixel of grayscale image
i.e. if pixel is other than black conver it into white.
if it is black then only it remain black.

You don't other people's homework.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You need to have an upper limit for the channels. Declare it as a constant in the TVRemote class.

When you try to increase the channel above that limit then have channel become 1. When you try to decrease it below 1 have channel take the upper limit.

The same as volume you should have code that checks if the volume has gone below 0 and prevent that. May be ignore it or print a message:

public void decreaseVolume() {
   if (volume==0) {
     // cannot decrease;
   } else {
      volume--;
   }
}

Also you should have checks at your set methods:

public void setChannel(int a) {
   if (a<1) {
      channel = 1;
   } else if (a>TOP_LIMIT) {
     channel = TOP_LIMIT;
   } else {
      channel = a;
   }
}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

We can't help you because we don't know what you want. From the description of your problem, I believe that even you don't know what you want

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You cannot execute java code from inside javascript.

You need to submit the data and then update the textfields:

String mobile = request.getParameter("mobile");
String username="";
String password="";
String message=null;

if (mobile !=null) { // the first time the page will render you will not have the mobile, so skip this part

  // use the mobile to get the data
  // depending on the results generate the appropriate html code
  // If there is any kind of error store it into the String message:

  try {
     if mobile OK   {
       message = "Data retrieved successfully";
       username = ....;
       password = ....;
     }
     else message="Could not get data";
  } catch (Exception e) {
    message = "An error has occured";
  }

}


// the rest of the HTML with the javascript validation code:

<%
if (message!=null) {
%>
Results: <%= message%>
<%
}
%>
<form name="mobileForm" action="" method="post">
   <input type="text" name="mobile" value="<%= mobile%>">
   <input type="text" name="username" value="<%= username%>">
   <input type="text" name="password" value="<%= password%>">
</form>

The above is simple, beginners way, but not very efficient.
For what you are trying to accomplish:

the values of other attributes like username and password should be automatically retrieved

you will need to learn Ajax.
But given the code you just wrote, you need to learn first proper jsp, understand that javascript is not java and cannot be mixed in the way you did, understand how java code inside the jsp is executed and how it renders the page, what happens when the page loads …

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Start a new thread and use code tags.

When you start a code tag: (CODE), finish it with the same by adding the '/' character. You added this code tag:
(CODE)
and then you finish it like this: (ICODE)

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Try this out then:
1. Click Start then Run and type in cmd then press Enter...this will bring up command prompt.
2. in command prompt type ipconfig /flushdns (you will get a message saying successfully flushed DNS)
3. type exit and try browsing again

If this does not work than do the following:
If this is Windows XP with SP2 then do the following:
1. Click on Start then run again and cmd should still be there press enter.
2. Type in (no quotes) "netsh winsock reset catalog" then press enter(in a few seconds you should get a message saying that system must be restarted)
3. Type exit then enter.
4. Click on Start then Turn Off Computer then click on restart then when system comes back up try browsing again.

If this is not a computer with SP2 let me know and I will post the instructions for Sp1.

Hi there,
I tried your suggestions, but I get the message:

>"The requested operation requires elevation."

What should I do? The IExplorer runs OK, but the mozila is not working.

Thanks

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I installed firefox days ago, and sometimes web pages can't open via it, the network is ok, anyone knows how to fix it? Thanks!

Hi, I have been having the same problem recently.

The mozila was working fine, but then when the latest version was installed, I couldn't see anything! All the pages that I tried returned blank. I tried the same urls with explorer and where displayed correctly.
I run a full system virus scan with my Panda Anti-virus, but still nothing.
I unistalled firefox and donwloaded it again, but still nothing. The firefox that I have at my laptop works OK, but I don't remember if it is the updated version.

Does any one know how to help us fix our problem?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Thanks for your help. I really appreciate it, you have really set me on the right path.I have just really had a lot of trouble understanding the whole coding in Java.I had experience with Visual Basics but it is more GUI than anything. When it comes to constructors there are multiple options with Java and choosing the right one becomes kind of confusing. But I will have to practice. Practice makes perfect.

Much appreciated.

Which one did you use and why. Also what method are you using in order to get the data from the selected Item of the Combo Box

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

java is not downloadable. Its illegal.. you will go to prison for that mate!!!!

Java is down loadable and free. Why are you spamming other people's threads like this?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

ClassA:

public static double add(double a, double b) {
   return a+b;
}

Main

import java.util.Scanner;

..................

Scanner scan = new Scanner(System.in);

// print message for user to enter input
String strA = scan.nextLine();
double a  = Double.parseDouble(strA);

// print message for user to enter input
String strB = scan.nextLine();
double b  = Double.parseDouble(strB);

double res = ClassA.add(a, b);

// print result
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You need to add get, set methods in your class in order to have access to the private variables:

public int getRank() {
   return rank;
}
public void setRank(int rank) {
   this.rank = rank;
}

The same for the title.


Do you know how to sort an array of integers. If yes then it is the same thing. You will have to use the rank variable though to do the comparison:

for (int i=0;i<movie.length;i++) {
  for (int j=i;j<movie.length;j++) {
     // use the movie[i].getRank(), movie[j].getRank() to compare and sort.
   if (movie[i].getRank() > movie[j].getRank()) {

  } else (movie[i].getRank() == movie[j].getRank()) {
      // If they are equal use the title as well
      if  ( movie[i].getTitle().compareTo(movie[j].getTitle()) > 0 ) {
         // the compareTo method is used to compare Strings
      }
  }

  }
}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
public static Object convesrion(Object obj, String s) {

}

If you search the API for reflect and look at the Class class, I think that you can find methods that:
Using a String create a Class instance of the given type.
Methods that check if something can be cast.

Also as String argument be careful to add the package as well: Class.forName("pack.A");

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I got your back.

Thanks mate.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Assuming a one dimensional integer array a[] has been declared and created with 100 elements:

for (int i = 0; i<=a.length; i++);
a = 5;

Assuming int b [] [] = new int [3] [3];
b[1, 1] = 5;

Strings students[] = {Pat, Tom, Mary, Anne};

Where you the one who down voted masijade? For what, for telling the forum rules?
When you registered, you must have read and accepted the rules, and know that what you asked is against them.

If you have questions post them, but what you asked is for us to do your homework. Post what you think and we will correct you or give you enough explanations in order to understand and find the solution.


PS: To masijade: You got Down-Voted for your previous post and I Up-Voted. You see now why I don't like this anonymous with no explanation providing voting system. Hope I don't get down voted as well :)

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Thnks. So the code should be

Scanner br = new Scanner(System.in);
        int num = br.nextInt();
        System.out.println(Integer.toBinaryString(num));
        System.out.println(Integer.toOctalString(num));
        System.out.println(Integer.toHexString(num));

Yes it is much simpler

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Scanner br = new Scanner(System.in);
int num = br.nextInt();
Integer a = Integer.valueOf(num);
System.out.println(a.toBinaryString(num));
System.out.println(a.toOctalString(num));
System.out.println(a.toHexString(num));

The toBinaryString and the other methods are static, so you don't need to create a new Integer object. What's the point of using the object created if you are going to pass as parameter the number used to create it?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

If you look the String API you will find a method that converts the String into a bytes array. I don't know though if this is going to be useful for you.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

First of all you have some spaces at the query that will not get you right results: "select * from members where username = ' "+username+" ' " Should be: "select * from members where username = '"+username+"' " Second: the "ResultSet" is the name of the class and the "username" is a String variable. Shouldn't you focusing more on learning simpler things, because form what I see from your code, what you are trying to achieve is way above your skills. You don't even know how to compare 2 variables or use class instances and you are trying to write a login page?

Anyway, first check the API for the ResultSet. There you will find methods that will help you extract the data from the ResultSet object. Better yet search this forum for examples on how to read data from the database.

As for your query it is better instead of this "*" to put the actual columns: "select username, password from members where username = '"+username+"' " Then take the username, password from the ResultSet and compare it with what you get from the GUI

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Whether it is for combobox or something else, it is irrelevant. What you need is a way to read the info from the database and put them into a list (Vector).
Then you can use the data into the Vector and put wherever you want (JComboBox)

Search this forum, there are examples on how to connect to database using java.
You will need to create the connection, then use the query and the connection to create a statement and then run it to get the results.
Search this forum for examples

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Did you look the API of the JComboBox. Do that and you will find a constructor that you can use.

Also, when you create a JComboBox using a String array, there is no constructor that takes as a parameter a String array, there is something else.

Take a look at the constructors and then post that you think you should do.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You need to add the comm.jar in your classpath.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The error is pretty obvious and has nothing to do with sql:

unreported exception java.sql.SQLException; must be caught or declared to be thrown

You are calling a method that throws an exception, and you don't catch it.
I mean why did you surround the DriverManager.getConnection with a try-catch?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

As far as the error handling you are already doing that. If you enter something other than a number, then the method:
Integer.parseInt, will throw an exception and the code will "go" inside the catch. You don't need to check anything:

public void actionPerformed(ActionEvent e)
	{
	try   {
    int principle=Integer.parseInt(jTextField1.getText());
    int downPayment=Integer.parseInt(jTextField2.getText());
// if the above values are not numbers then the program will take you automatically to the catch.

    int temp = 0;
    resultArea.setText("");		
			if (p<b)  {
// do the calculations. If you made it this far, means that whatever you entered where integers.
                        }
		} catch (NumberFormatException ex) {
// The above exception is thrown when you don't enter a number as argument to the parseInt, parseFloat, .... methods

     System.out.println("Invalid Number");
	resultArea.setText("Input House Price");	
		} catch (Exception e) {
// Catch the above in case something else happens
     System.out.println("An error has occured: " + e.getMessage());
}
}

As for the ComboBox, the examples you posted seems to work. What are you trying to accomplish that doesn't work?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Lots of errors showing.. When compiling....

WOW !

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

hi
the follwoing errors appears after compilation
cannot find sympol variable ap
and in the main class
cannot find variable initnode
cannot find variable nodo .......etc

Without code we cannot say much. But it is probably because you haven't declared those variables, or you declared them in a place where they cannot be seen by where you call them. Use the above suggestion first, see if the problem is solved and then post again.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

How to counte each letter

Check the String API. There is a method that lets you take each character from a word (String)

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I can write this code but I can't Complete it

As masijade said post what you have done so far and we will see what we can do for you.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The comments in the methods tell you exactly what you need to do. All is needed is some if statements and reducing or increasing the mylocx or mylocy by one.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

A Driver class is nothing special. It's just a name, and it means the class in which we call all our methods. The class with the main method that we call in order to run the application.

class Methods {
  public static int add(int a, int b) {
    return a+b;
  }
  public static int sub(int a, int b) {
    return a-b;
  }
}

class MainDriver {
  public static void main(String [] args) {
      // read from the keyboard or the arguments 2 numbers:
     int a = 5;
     int b = 6;
     int c = Methods.add(a, b);
     System.out.println(c);

     int d = Methods.sub(a, b);
     System.out.println(d);
  }
}

Try to avoid declaring methods in the driver class. Just have the main and call whatever you need in the main in order to run your application.
That will include initializing objects and calling their methods:

class Person {
  public String name = "";
  public int age = "";

   public Person() {

  } 

  public Person(String n, int a) {
   name = n;
    age = a;
  }
}

class MainDriver {
  public static void main(String [] args) {
      Person p1 = new Person();
    p1.age = 12;
   p1.name = "Name 1"

   Person p2 = new Person("Name 2", 10);

System.out.println(......);
System.out.println(......);
  }
}

You have your Person class and in order to test it, you created a "driver" class with a main method.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

unless your onclick() methods does something else.

That is why I asked for the code of the onclick() methods. He may be going to the other jsp in some way that doesn't pass the parameters at the request.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I assume that you can add an actionlistener to the menuItem using the addActionListener method. Look the API. When the menu is selected the actionPerformed method of the ActionListener is automatically called.

I believe that there is a remove method that removes components from the JFrame. I have never used it before, but I believe that if you add a JPanel to the JFrame and then you call the remove method with argument the same JPanel, it will be removed.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

first of all what the javascript methods that you have at the onclick do, and second why don't you submit without the onclick() ? Since it is type="submit" once the button is clicked the form will be submitted anyway.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Use these classes:

JMenu
JMenuBar
JMenuItem

check the api for them.

The ideas is:
You create one JMenuBar.
You create some JMenus and you add them to the one JMenuBar.
You create some JMenuItems and you add them to your JMenus

Also there is this:
http://java.sun.com/docs/books/tutorial/uiswing/components/menu.html

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

1) Have you read the rules of this forum before posting?

2) Start by creating objects with properties the columns described at the tables.
3) Read about the Vector class.
4) Will it require a database?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
import java.util.Scanner;
import java.io.File;
import java.io.IOException;
import java.awt.image.BufferedImage;
import javax.imageio.imageIO;
import.java.awt.Color;
public class FinalExam
{
	public static void main(String [] args) throws IOException
	{
		String Xfile=args[0];
		if(Xfile.equals(""))
			System.out.println("Enter a valid file!");
		else
		{
			File imageFile = new File(Xfile);
			BufferedImage storedImage = ImagIO.read(imageFile);
		}
	}
}

Thank you,
Kanishka Dilshan.

Totally wrong. Shows a lack of understanding of arguments. And if you complain that you are not very good with java, why do you give wrong suggestions and code.

This will never run:

String Xfile=args[0];
		if(Xfile.equals(""))
			System.out.println("Enter a valid file!");

the way you think. You will get an ArrayIndexOutOfBoundsException.

I will give you some time to figure it out on your own before posting again.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Alright, whoever voted that down be man enough and stand up to admit to it (which is probably the reason (s)he didn't use the "rep" link, as that transmits the userId along with it).

Who was that didn't like the fact that it was pointed out the user crossposted, without being respectful enough to refer to the original post, so that anyone answering here would more than likely simply been wasting their time by making suggestions that have already benn made, as happened above?

In that case, I will ask you if also pay bills your partner has already paid? Do you sweep the floor 5 minutes after someone else has already done it? Etc, etc. All of these are a waste of time and/or money (which a waste of time is a waste of money, even if not always yours), including the cross-posting.

So, who took offense at the fact a cross-post was pointed out (in an attempt to save others from wasting their time), but didn't take offense at the cross-post itself?

And, for the record, I have nothing against cross-posting to another site, as long as the OP makes reference to the other post so that any one responding can see what's already been suggested rather than wasting their time repeating things.

Edit: Then again, it was probably the OP that voted it down, since the repeat answer is already voted down and the truth is simply too much to bear (i.e. (s)he was not provided with …

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

His is very short, hates milk, doesn't need to draw circles and absolutely hates being called short.

My answer : Aisaka Taiga...

I was thinking of Full Metal Alchemist (doesn't need to draw circles).

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

What you ask is rather difficult. In order to know when the table has been updated, you need to add triggers to your table.
Then write a PL/SQL function that executes when the "trigger" is triggered.

The rest are a bit blurry to me since I am not familiar with that kind of deep SQL coding.
I think the you can call java methods in your triggers in order to update your application. But how will you know that application is running in order to update it?

Does it have to be automatically? Can't you just have a button that reads again the DB table, whenever the user clicks it?
What are you trying to accomplish in general?

If this doesn't cover you, try the database/sql forum of this site

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Because you add it only to vector and not the JList:

gf.vf.add(file);

You added it successfully to the Vector but where is the code that adds it to list?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Your brackets are all over the place. You open them and you don't close them correctly. Start over and this whatever opens close it, and write code inside it.

At the while loop you don't update the len value inside it. You say that "Please enter at least 15 characters" have to be entered but then you don't anything about it. The loop will continue running and the len doesn't change.
Shouldn't you do something to change it?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

This is what is displayed:

<option>[B]MCA[/B]</option>

This is what it is sent with the request:

<option value="[B]MCA[/B]">MCA</option>

Meaning that there will be cases that what you display is different from what you want to sent:
Example:

<select [B]name[/B]="product">
<option [B]value[/B]="000-001">Product Name 1</option>
<option [B]value[/B]="000-002">Product Name 2</option>
</select>

Remember that you send the value attribute at the request and you get it using the name. Like you did: request.getParameter("product") will return one of those: 000-001, 000-002. Not what is displayed between the "option" tags

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

So you want us to read to you the code line by line. Do you know how methods are called? If yes, it is pretty simple: Objects are created and their methods are called.
Have you tried reading the API or reading a tutorial on how to creat guis?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
public class Algarv {
    public static void main(String args[]) {
    int numbrid = 0; // Proovime kohe algusest
    int loendur = 0; // Loendame üles, et pärast lihtsam oleks
    while(loendur < 100) // Eelkontrolliga, t2idame kuni see on 100
        {
            numbrid++;
            if(numbrid % 2 != 0)
                {
                    int abi = 3;
                    while((numbrid % abi != 0)&&(abi <= ((numbrid - 1) / 2)))
                        {
                            abi++;
                        }
                            if(numbrid % abi != 0)
                                {
                                    loendur++;
                                    System.out.print(numbrid+" ");
									System.out.println(loendur);
                                }
                }
        }
}
}

For future reference, please have your comments in the code in English

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

that is.,
say, ob is an Object,
int i = Integer.parseInt((String)ob);

Only if ob can be cast to a String. Of course you created the JTable and know better what you put in there. Since you know what you put to each cell, cast it to the appropriate class, and act accordingly

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

user can go the browser and type the url he wants

Then after the user logs in put in the session the username and the user role (ADMIN or USER)

Then at every page get the info from the session and if someone has gone to an ADMIN page when in the session the role saved is USER then use javascript to go back and display message.

Even in the more secure sites, any one can just type the url. But if they are not logged in they are reditrected.

Also at logout remove those values from the session.

After login:

// 'username' variable the one the user entered and 'role' the one // taken from the database. If login successful put those values:
session.setAttribute("USERNAME",username);
session.setAttribute("ROLE",role);
// and redirect to the next page.

At the begining of every page

String username = (String)session.getAttribute("USERNAME");
String role = (String)session.getAttribute("ROLE");

// if the above values are null, means that the user has not login.
// if this page is to be accessed only by an ADMIN the redirect

// After logout

session.setAttribute("USERNAME",null);
session.setAttribute("ROLE",null);