masijade 1,351 Industrious Poster Team Colleague Featured Poster

You see the two Paths you listed? Those are not the same file. Take a close look at the actual Filenames, then delete the one in lowercase.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

JavaScript runs on the client. The perl would run on the server. Tomcat has nothing to do with either of them.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

At the moment, if you are just learning, neither.

Learn how to write programs using a simple tet editor (with syntax highlighting, maybe), while compiling, executing, and packaging from the command line. Once you have a good grip on all of that, then it would be a good idea to start worrying about an IDE.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

A note on the file separator, the command line intrepreter is the complete reason why "\" is always used on Windows. Almost, if not, all programming languages can use "/" for paths in Windows, but the command line interpretor interprets "/" as the option argument indicator, so it needs something else for the file separator, and that became "\".

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Now that you have a decent driver, I would say to change ("jdbc:mysql://localhost:8009/login? user='root'&password='mdas'"); to ("jdbc:mysql://localhost:8009/login", "root", "mdas"); Also, that space between the ? and the word user in the original url will cause problems anyway, even if the DriverManager does accept the url with user and password as parameters on the url, as there should not be a space there.

The web.xml is placed directly under WEB-INF, not any of its subdirectories.

And, no you do not need to install apache, but it is advised to use a real browser as the front end (in this case apache) and connect to the tomcat locally through the webserver (in this case using mod_jk).

masijade 1,351 Industrious Poster Team Colleague Featured Poster
masijade 1,351 Industrious Poster Team Colleague Featured Poster

Well, I see no <HTML> </HTML> or <BODY> </BODY> tags, so, if that is suppossed to be a complete HTML document, it is not.

I, myself, don't know how those OLE packages are suppossed to work, so I can't even begin to say whether this tip is correct or not.

All I can say, is, that if this is suppossed to be a complete HTML document it is not.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

We are not going to do your homework for you. Make an effort, then, when you have an actual problem, pst what you have up to that point and state, explicitly, what the problem is.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Try downloading a newer version of the Driver.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

What DB version are you using, and what version of the driver are you using.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Here

String name =JOptionPane.showInputDialog("Enter name of course: ");
          //downcast all strings into int float etc
   String inputMarks =JOptionPane.showInputDialog("Enter course marks: ");
           int marks = Integer.parseInt(inputMarks);
   String inputcHr =JOptionPane.showInputDialog("Enter course credit hours: ");
      int creditHr =Integer.parseInt(inputcHr);
   }


      Course c1 = new Course(name, marks, creditHr);
      courseResult.add(Course c1);

I assume you meant

String name =JOptionPane.showInputDialog("Enter name of course: ");
          //downcast all strings into int float etc
   String inputMarks =JOptionPane.showInputDialog("Enter course marks: ");
           int marks = Integer.parseInt(inputMarks);
   String inputcHr =JOptionPane.showInputDialog("Enter course credit hours: ");
      int creditHr =Integer.parseInt(inputcHr);


      Course c1 = new Course(name, marks, creditHr);
      courseResult.add(c1);
   }

not the move of the "}" character, and the change of the add method (which would have produced a different error after you resolved the error with the "}" symbol).

masijade 1,351 Industrious Poster Team Colleague Featured Poster

I will go out on a limb and say that the problem arises form the following:

filename = ConsoleInput.readLine( "Please Enter filename");
rec.save(filename);

As I am fairly sure that you will be entering the filename as follows:

C:\Bogus\Path\To\File.txt

if this is the case you need to modify the above two lines as follows:

filename = ConsoleInput.readLine( "Please Enter filename");
rec.save(filename.replaceAll("\\", "\\\\"));
// or rec.save(filename.replaceAll("\\", "/"));

As otherwise, you are saving a String with single "\" characters in it, and so, when you attempt to open the file it will interpret the "\" and the character directly after it as special constructs, so you need to escape each of those single "\" characters with a double "\" character, but since "\" is a special character in the replace Strings, you need to escape it there as well, which is the reason for the double and then quadruple "\" characters in the replace statement. The double "\" will find all instances of a "\" and the quadruple "\" will place a double "\" in all those places.

I hope this makes sense to you, as I can't really explain it any better.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Error (since 1.5) is another "excpetion" class. Here a quote from the API

An Error is a subclass of Throwable that indicates serious problems that a reasonable application should not try to catch. Most such errors are abnormal conditions. The ThreadDeath error, though a "normal" condition, is also a subclass of Error because most applications should not try to catch it.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Well, read the API doc. Which package does it say JOptionPane belongs to?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

First of all, never place anyting into the "bin" directory of jdk (or really in any directory of the jdk/jre).

Second of all, does your class contain the following method defintion:

public static void main(String[] args) {
  // your code here
}

and I mean that exact method definition? Bcause the error you listed, says it does not.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Error you get is: "IOException returned is:
(The filename, directory name, or volume label syntax is incorrect)"
Did you check if you're giving the path correctly? May be it's some simple bug like using "/" instead of "\" (/ is for Linux/Unix and \ for windows as you know)

Just as a note. You can use "/" in Java on both Windows and all Unix flavors (I haven't got a Mac to try, but I'm fairly sure you can use it there, too). So, for convenience sake (and efficiency sake, since it will eliminate errors such as using a single, instead of a double, "\") it is better to either always use "/", or, if you don't like this, to always use File.separator

masijade 1,351 Industrious Poster Team Colleague Featured Poster

In mysql you not only have to create a user and set a password, you also have to designate from where (and how) that user is allowed to connect the DB. Per default, root can only connect from localhost using the sock file, but, in Java, you will be attempting to connect over TCP. So, read the MySQL documentation (namely the GRANT statement) and add a root@localhost entry.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

JavaScript != Java Find a JavaScript forum.

But, if the page is generated, rather than static, than have that page include a hidden field containg the date at the time of the request.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

What is wrong with the thread at the top of this forum page?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

You do realise that this thread is over a year and half old, right?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

You type javac config.java to compile and java config to execute (not java config.java ).

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Those were valid statements. A forum is not the place to learn a language from the ground up. It just isn't the right medium. Go to Sun's Tutorials web site and do the tutorials, from top to bottom, starting with Getting Started.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Just read the API for String. Once you have read the input there are two methods in String that do exactly what you want.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

I don't think there is anything wrong with it. You said it yourself, it is for building enterprise applications. For building a 'simple website' use 'simple HTML', or PHP, or any form of CGI. JSP is not meant for a 'simple website' and that is actually all there is to it. You can use it to create a 'simple website', but that is probably overkill. I know in your class, you must use JSP, but that was the universities (and/or your instructors) choice, but that doesn't change the facts.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

True but I feel that would be easier ! :)


As someone quoted earlier you've deceptively missed a few other things:
1. Installation of DB?
2. Creation of DB table?
3. Code to create the DB connection?
4. Readup how to do step 1, 2 and 3 or ask someone???
I sure agree that once you're done with all this you'll "simply set of a query with the username as the search string and return the id".


Here is the fuss/muss we'll have to do if we use flat file (see the code at end). Self-regged search routines? std::map gives it. map::find().
Abt the "single stmt and you're done part" as I said earlier, it's not really true.


See the return type of std::map::insert(). It does this for you. Again you don't write no code.

#define MAX_LINE_LEN 100

int main()
{
    FILE * pFile = fopen ("user_info.txt", "w+");
    if( ! pFile )
    {
        cout << "Could not open file" << endl ;
        return 1 ;
    }

    for( int i = 0; i < 10; i++ )
    {
        char dummy[50] ;
        itoa(i, dummy, 10) ;
        fprintf (pFile, "%s %d\n", dummy, i);
    }

    rewind (pFile);

    map< string, int > usrInfMap ;
    char str [80];
    int j;
    while( EOF != fscanf (pFile, "%s %d", str, &j) )
    {
        usrInfMap[str] = j ;
    };

    fclose (pFile);

    map< string, int >::iterator it = usrInfMap.begin();
    for( ; it != usrInfMap.end(); it++ )
        cout << …
masijade 1,351 Industrious Poster Team Colleague Featured Poster

Storage of the list of Username vs ID most probably has to be done persistantly. I would recommend not to use DB if this is the only reason you want to use it. Rather go for a simple flat/txt file would be easier.

I don't know why you feel storing it in a flatfile is better. That requires that you load the entire list while running, or that you write your own search routines to search for the user/id combination. With a DB you simply set of a query with the username as the search string and return the "id". No fuss, no muss. No loading the entire list into main memory, and no self-rigged search routines. And storing new user/id combos is just as easy as finding one. A single statement, and you're done. And this includes the possibility of a new user attempting to use the same name as a current user, when the username is the primary key, as the insert will fail with a primary key validation. With that, you no longer even have to check yourself whether a new username exists or not. Simply try to add it.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Hi, I'm trying to use the replace() method to take out all instances of " "
, (space) with an underscore, ("_"). I'm doing this because I'm using URLs to connect to a servlet. I keep getting this error:

replace(char,char) in java.lang.String cannot be applied to (java.lang.String,java.lang.String)

url.replace(" ", "_");

This is how I wrote my code:

url = url.replace(" ", "_");

What am I doing wrong? Any suggestions would be most welcome.

Thanks,
chuck

Do you notice something about the highlighted protions of the error message?

change url.replace(" ", "_"); to url.replace(' ', '_');

masijade 1,351 Industrious Poster Team Colleague Featured Poster

You should be overriding paintComponent, and not paint. You also need to call setOpaque on the component.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

perlcc that comes with the perl distribution

masijade 1,351 Industrious Poster Team Colleague Featured Poster

You run a servlet through an application server, not from the command line. Do you have an application server? Tomcat, WebSphere AS, Bea WebLogic, Sun AS, etc, etc.

Once you have one (you can download and use Tomcat for free), read its documentation to find out how you deploy an application, then deploy your servlet, and try to access it with the browser.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Really, I had no idea you could grab input from a JOptionPane without some sort of getText() method

JOptionPane's showInputDialog and showInternalInputDialog will return a String, its showConfirmDialog, showInternalConfirmDialog, showInternalOptionDialog, and showOptionDialog return ints. With the OptionDialogs that is the index of the array of options passed.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

The message you got was only a compiler warning. The class itself still compiled normally. If you want to get rid the warning change

celsius = ((5.0 / 9) * (fahrenheit - 32));

to

celsius = (int) ((5.0 / 9) * (fahrenheit - 32));

and the warning goes away.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Use double for your fahrenheit and celsius and change
celsius = (5 / 9) * (fahrenheit - 32);
to
celsius = (((fahrenheit - 32) / 9) *5)

You do not need to change f an c to double, you just need to make sure that you do double math (if all you want is the nearest whole c grad).

The formula used initially is okay, except for the fact that he is not doing "double math", so the quickest fix, that works, is as follows:

change

celsius = (5 / 9) * (fahrenheit - 32);

to

celsius = ((5.0 / 9) * (fahrenheit - 32));

@MacGyver Orca
He gets his input here:

fahrenheitString = JOptionPane.showInputDialog("Tempature in Fahrenheit: ");
masijade 1,351 Industrious Poster Team Colleague Featured Poster
masijade 1,351 Industrious Poster Team Colleague Featured Poster

Is it not that ActionListners for both buttons would be different objects? If so you'll run into same problem. (both ActionListner objects have to know both Button objects). Instead on click of A, update the value in "common place" and on click of B pickup the value from "common place" and do the needful.

It does not need to be different ActionListeners for each button. That normally only happens if you use anonymous inner classes for the ActionListeners, but you don't have to do that. And, as a matter of fact, since the action of each buton depends on a possible previous action of another button, you should use the same ActionListener for both buttons and differentiate the action according to which button was pressed and whaqt action was previously done by using an if statement and a state variable.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Well, if the instances of the Buttons themselves are known to the ActionListener (i.e. they are instance variables that the ActionListener has access to) you can simply use getText() to get the displayed value on the button.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

anyone can help me..
i have a task to coplete
below is the question :

create class called Arithmetic for performing arithmetic process.
use two integer variables to represent the private data of the class. provide a constructor function that enables an object of this class to be initialized when it is declared. the constructor should contain default values in case no initializers are provided.

provide public member functions for each of the following :

a) accepting values for Arithmetic variables
b) menu for Arithmetic process option.
c) addition of two numbers. this function should return a value
d) substraction of two numbers. this function should return a value
e) multiplication of two numbers. this function should return a value
f) division of two numbers. this function should return a value
g) printing Arithmetic numbers. this function should return a value

And what part of this do you not understand, or are you having a specific problem with?

We are not just simply going to do your assignment for you.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Use PreparedStatement and new Date (using java.sql.Date not java.util.Date).

If you question is how to formulate a query in general, then please find an SQL forum.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

So what is your question?

No one is going to write these programs for you.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Try this way ;)

public String ins_Deposit(String userid,int amount,String branch,String bank) throws SQLException
{
Statement ps = null;
[B]String output;[/B]
try
{
ps = conn.createStatement();
String query="INSERT INTO BANK_TRANSACT VALUES('"+userid+"',sys_date,"+amount+",'D','"+branch+"','"+bank+"')";
int result = ps.executeUpdate(query);
if(result>0)
[B]output = [/B]"Transaction successfully completed,amount will be credited to your account within 24hrs. ";
else
[B]output = [/B]"Bank timings are between 8 AM to 8 PM IST,Record not inserted";
}
catch(SQLException e)
{
System.out.println("Unable to get Data: " + e);
}
[B]return output;[/B]
}

That will probably return that "output" may not have been initialized (if an Exception occurs before the if statement) so either initialize output to a value, or assign output a value in the catch block.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

isn't that what I said in my post ;)

The "firstly" and "thirdly" would have been a little misleading, IMO, since he was already getting the length and he already had a for loop (just wasn't entering the values) and those points made it sound as though he still needed to add a new question for the length and create another for loop, which he didn't.

Like I said, that is all IMO, but that's the way I read it.

;-)

Edit: @OP I missed the totalling part. For that simply add an int declaration before the for loop and then total += num inside the for loop, so that you are totaling and storing the values inside the same for loop.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

What happens, if it makes it all the way to the last nested if statement and that statement evaluates to false instead of true? What value would c have then? None because it hasn't been initialised. Add an else to the last nested if and the error will go away.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Look at this from your code:

try { //Reads keyboard input and acts accordingly
            input = stdin.readLine();
        }catch (IOException ex) {
            System.out.println("Problem reading from the keyboard");
        
        iInput = Integer.valueOf(input); // convert String to Integer
        }

You convert your string input to an integer only when an exception happens. You need to move the closing brace from the catch block to a point before the iInput = line.

And, as a matter of fact, your indenting implies this to the reader, but the braces define something else, and it's the braces that count.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

So what's teh question and where is teh "class Scanner " ?

Scanner is a part of the JDK Since 1.5 (if not 1.4.2).

@OP

Before you start the loop, you need to declare and initiate an array with the variable "value" after your first question.

int arrayname = new int[value];

Then, inside your loop, insert each of the values, as you get them, into your array.

arrayname[i] = num;

And your for loop should go from 0 to < value and not from 1 to <= value.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

df

masijade 1,351 Industrious Poster Team Colleague Featured Poster
package class card;

I'm sorry, but don't you see anything wrong with this line? Both package and class are reserved words of a type that can't be used together, so it is more than passing strange to see them one after the other for one. For another I don't believe you can have a space in a package name (call me an idiot, but .....). For another, since class is a reserved word, you can't use that as a package name anyway. This line should probably be either be

package card;

or (and I think this more likely)

public class Card {

And in fact, in the first of those files (Card.java) in the thread you mentioned, that is exactly the way it is, except the { is on the next line, rather than on the current line.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Well, first of all, it would be much safer and reliabe to use a PreparedStatement rather than a Statement.

Second of all, a JSP is meant for viewing, changes/actions should happen in a Servlet, and scriptlets should not be used at all in JSP.

Also, if you must actually check before inserting, use a Select. But simpler (if the item you would need to check is the Primary Key) is to simply attempt to insert it and catch the SQLException. If a Primary Key constraint violation is returned, the record already existed.

And the only thing you can do from the server side, is to return an error page, or return to the form. You can't pop up an alert before the submit, unless you want to attempt to use AJAX, as those alert popups that you are probably thinking of, are JavaScript and the JavaScript running on the client would have no access to the database.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

No. The query and setString statements can remain the same. It is, however, not recommended to use scriptlets this way. The DB code should be moved out to a bean. Scriptlets, AFAIK, are only still supported for backwards compatability reasons.

You don't want to be backwards do you? ;-)

masijade 1,351 Industrious Poster Team Colleague Featured Poster

.pm files are "Perl Modules" rather than perl scripts. They are Perl's objects.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Change mv $file "$file".das to mv $file ${tmp}.das . It was just a typo.