~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

This probably seems to be more of a MySQL problem rather than a Java one; you might also want to try posting this to the official MySQL forum or Daniweb's MySQL forum.

Some interesting threads which I stumbled upon which make it seem as if this is a problem with older versions of MySQL:

http://www.vbulletin.com/forum/showthread.php?121120-SQL-Error
http://forums.mysql.com/read.php?26,6528,6528
http://bugs.mysql.com/bug.php?id=3611

I found one thread related to this topic. However, this thread discusses only Java web-applications.

That really shouldn't make a difference if it is MySQL which is the problem maker here. There is not a frightful lot you can do on the Java side except ensure that the user input is passed to the database engine as "utf-8" encoded string and set the connection properties to support the same.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

`n` is an integer (primitive type) and doesn't have a `length` property/attribute. You just need to check whether the passed in number (probably the number of animals in a Zoo) is a valid number; if not, use 1 as the default.

class Animal {}

class Zoo {
  private Animal[] animals;

  public Zoo(int n) {
    // check if `n` is invalid; if it is, reassign & make it 1
    this.animals = new Animal[n];
  }

}

Give it a shot.

EDIT: Also, you don't need a *return* statement in a constructor. You might want to read this once again.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

@Nitin: What happens if you need to perform this 'discounting' check multiple times? What if the requirement changes to allows for only fixed set of 'memberIds' to avail the discount?

IMO, you should ask this question from to the entity in consideration rather than querying/deducting it yourself. One solution would be to have either a method in the Customer class or have a interface which is implemented by both Customer and Member which has the method isEligibleForDiscount() . Then you can have code which does:

public class Transaction {

  public void giveDiscount(final Customer c) {
    if(c.isEligibleForDiscount()) {
      // give discount
    } else {
      // no discount
    }
  }

  public void printReceipt(final Customer c) {
    if(c.isEligibleForDiscount()) {
      // print discounted receipt
    } else {
      // print usual receipt
    }
  }

}

OR

public class Transaction {
  // here Discountable is an interface implemented by both
  // Customer and Member so they are really not required
  // to be part of the same type hierarchy.
  public void giveDiscount(final Discountable c) {
    if(c.isEligibleForDiscount()) {
      // give discount
    } else {
      // no discount
    }
  }

  public void printReceipt(final Discountable c) {
    if(c.isEligibleForDiscount()) {
      // print discounted receipt
    } else {
      // print usual receipt
    }
  }

}

With the change in requirements, there might be other ways of doing the same but ensure that none of those approaches which you follow end up probing too deep in the Customer object without proper abstractions.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I think it is strange that someone would try to turn a compliment into something negative or am I just being baited.

This is "teh Internet"; where reason fails, where a wolf doesn't require a sheep's clothing and 10 year olds claim to have a house in Hollywood city (OK, maybe not the last one). In case you still don't realize it, this outcome was kind of predictable given your post content and your sig links.

BTW, looking forward to your next thread; Dani II -- The confession ;-)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

There are rankings based on three criteria: posts, reputation and solved threads; the top posters based on solved post count shown here is I guess what you are looking for...which fortunately filters out some of the posting game points. :-)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

This topic has been debated a lot in the past and the conclusion is that there is always a possibility of false positives i.e. a positive conclusion that user has posted code but not used code tags when that isn't really the case. This is a risk Dani isn't ready to take plus the implementation of the added functionality which would be required for vbulletin supporting this increases the effort required.

A couple of forums out there do this (I guess Cprogramming is one of them) but unfortunately this is a no-no for Daniweb. But given that it has been quite some while this topic was discussed and as you have anyways resurrected it, let's see... :-)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Which browser do you use? What kind of privacy settings do you have for that browser? Are you using Firewall? If yes, have you added Daniweb to the list of trusted sites(if there is one)?

AFAIK, Daniweb solely relies on cookies for session tracking, so anything which messes with that messes with Daniweb navigation.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

AFAIK, there is no standard way of sending encrypted passwords to the database. Why does passing data between validation code to the db connection code seem icky; after all, it's just in-memory transient plain text data that you are passing between classes and not something you are writing out to the file system.

If you end motivation is over the wire security (making sure that no one tampers with the password sent over the wire in plaintext), you can configure MySQL to accept SSL connections (at least this is what this article says). One thing to look out for is to confirm whether this SSL connection is a single time connection used only for grabbing the Connection or does it also encrypt all the communication which follows by using that Connection object since SSL has a distinct overhead when compared to normal socket communication.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Don't create multiple Scanner objects for the same underlying stream. As far as the "VM just stays there" is concerned, `nameScanner.nextLine()' is a blocking call which waits for a line to be entered via the stdin.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

What exactly is the problem that you are facing? Are you facing compile time or runtime errors? If compile time, what are the errors you are getting? If runtime, what's the expected output, what are you getting instead?

Provide more details.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Unfortunately, we do not live in a perfect world, and this doesn't work because of type erasure.

Why doesn't it work? Instantiating a type parameter won't work, but instantiating parameterized classes which accept a type argument will. The below snippet won't work, but what you posted will.

// doesn't work
public class MyGenericClass<T> {

    private T item;

    public MyGenericClass() {
        item = new T();
    }

}
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

The error is exactly what is says: the system can't find the file "C:\Program%20Files%20(x86)\glassfish-3.0.1\glassfish\modules\gf-client.jar" because of spaces being interpolated to %20 (this might happen when the file path is treated as a URI). This seems to be a bug in Glassfish as said mentioned here: https://glassfish.dev.java.net/issues/show_bug.cgi?id=12769 and has been fixed in the 3.1 version. If you don't want to upgrade, just reinstall Glassfish to a location which doesn't contain spaces (e:\software\Glassfish) and it should solve the issue.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

It's a good idea to use a Buffered stream/reader even for small files. That way, if you encounter performance problems later on, you can tweak the size of the buffer and improve performance without changing a lot of code (just changing buffer size).

But like all performance related things, code tweaked to specific scenarios performs much better than generic code. For e.g. in some cases, it might make more sense to read the *entire* file in a single sweep thereby reducing the system calls even further. Profiling is your friend.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Don't compare Strings using the == operator; when used with primitives it compares values whereas when used with reference types it compares references. If you need a logical comparison (comparing values), use the `equals()' method for objects (which falls back to reference comparison if the object in consideration doesn't override the `equals()' method of the Object class).

Also, why are you creating a new 'Car' object just for display purposes? A simple loop over the existing Car array should do the trick. Regarding the size of the new temporary array, is it really required that you use an array? Whenever acceptable, using a List instead of an array is much more easier to work with and flexible. Something simple like this should do the trick:

final StringBuilder buf = new StringBuilder();
for(final Car car : cars) {
  buf.append('Color: ').append(car.getColor()).append('\n');
}
textView.setText(buf.toString());
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

The warning comes up when a class whose objects are capable of being serialized is missing an explicit version ID (very much similar to giving version numbers to your software releases). This must be because either JFrame or the superclass/super-interfaces of JFrame implement the Serializable interface.

You can do away with this warning by adding a version ID to your class;

public class Test implements Serializable {
  
  [public|protected|private|default] static final long serialVersionUID = 1L;

}

This doesn't mean that when no serial version UID is provided, none is used during serialization. It just means that the compiler would then generate a version ID for your class which is subject to the physical structure of your source code and can change by adding/deleting/moving around methods and variables. Serial version UID is especially critical when objects of a given class are persisted or sent along the wire. By keeping the serial version UID same, you can make non-interface breaking changes to your class.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> 1. Line endings are still hacked as there is no readLine.

Raw input streams shouldn't be used for reading character data anyways so this is a moot point. Byte based streams don't have a notion of "line" hence no "readLine()" method. You make the mistake of assuming streams would always be a character based stream.

> We can already have the buffering facility via the proper read() function

No, that's not buffering capability; that's the capability of being allowed to read in multiple bytes in a single sweep. In this case, you don't provide buffering but ensure that minimal number of calls are made to the FS by selecting an appropriate byte array size. Each "read()" call would still need to access the File system in your case. In case of buffered streams, it might so happen that the "buffer" size is much more than the size requested in which case, multiple read invocations can be made without touching the file system.

Is all this impossible to do ourselves? No definitely not, but the question which needs to be asked here is that, do we really need to do this ourselves? :-)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Depends on the kind of updates you are making; are they for the entire file or only parts of the file? If for the entire file, read the file line by line and write out the modified line to a new file. If the updates are targeted updates and only for selective lines in the entire text file, look into the RandomAccessFile class though I must say it's a bit tricky to get right.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

But then why do the docs say that calling markSupported() on an object of FilterInputStream's subclass (like BufferedInputStream) performs in.markSupported() where "in" is the underlying InputStream ?

Because that's what it is; calling mark/reset/markSupported on FilterInputStream *delegates* the call to the InputStream instance with which the FilterInputStream was created. This instance can be *anything* which extends the InputStream class.

At one place it says that that BufferedInputStream adds the mark functionality to InputStreams. If its simply calling the underlying streams mark() method, how is it adding anything ?

I think you are reading docs the wrong way; if a given class *overrides* a given functionality of its superclass, you read the Javadoc for that overridden part instead of the original one present in the superclass.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

It's a bit complicated since interacting with external applications which can differ based on the OS/file types isn't exactly Java's forte.

Hardcoding application name/paths works but has a couple of drawbacks:

  • Users would typically want the file to be opened with the application with which they have associated the file type. For e.g. computer savvy users normally use other text editing tools like notepad++, vim etc. for editing files instead of notepad.
  • The application selection IF ELSE checks need to go down one more level to accommodate different Operating Systems. E.g. windows, linux etc.

You'd require a library which abstracts the file association lookup, something like JDIC. This library isn't exactly user friendly or feature complete but gives you the basic file association lookup functionality. It might be a bit of overhead to include this big a JAR just for file association but the choice is yours. A sample snippet:

package home.projects.misc.classloader;

import org.jdesktop.jdic.filetypes.Action;
import org.jdesktop.jdic.filetypes.Association;
import org.jdesktop.jdic.filetypes.AssociationService;

public class ProcessTest {

    public static void main(final String[] args) throws Exception {
        AssociationService s = new AssociationService();
        Association o = s.getFileExtensionAssociation(".doc");
        Action appAction = o.getActionByVerb("edit");
        String appName = appAction.getCommand().split("\" ")[0].replaceAll("\"", "");
        final ProcessBuilder pb = new ProcessBuilder(appName, args[0]);
        final Process p = pb.start();
        System.out.println("Starting wait");
        System.out.println("Wait status: " + p.waitFor());
        System.out.println("Wait complete");
        new File(args[0]).delete();
    }

    public static void p(Object s) {
        System.out.println(s);
    }
    
}

Play around with the API to get it working as per your specific need.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

It's also a possibility that "ping" is disabled on that machine which leads to dropped packets hence the timeouts. Another thing you can try out is "telnet". Try the command telnet <host> <port> for your MySQL and FTP ports. If it works for MySQL and not for FTP server, we might have something there. In any case, post the entire IOException stacktrace.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I don't really see a problem here; the program when run outputs a file "assault_tropper.bmp" which is around 67 MB due to a bug which causes the length to be shown as 67 x 10^6.

There are couple of things you can do to debug this:
* Write out the idx0 file and immediately read it using the RAF in the same sample code. Verify that the numbers written are indeed the numbers which you intended
* Write out the main cache file (by packing the resources) and in the same sample code try to unpack the now written resources.

If both the above samples work out fine, I don't see why a combination of them won't work.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

But how could I delete the file exactly after closing Notepad (or any other lookup program)?

In that case, you need to ditch the Desktop class and look into the Process/ProcessBuilder classes and the `waitFor()' method. Some sample code:

public class ProcessTest {

    public static void main(final String[] args) throws Exception {
        final ProcessBuilder pb = new ProcessBuilder("notepad", args[0]);
        final Process p = pb.start();
        System.out.println("Starting wait");
        System.out.println("Wait status: " + p.waitFor());
        System.out.println("Wait complete");
        new File(args[0]).delete();
    }

}
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Too little information to help you out. Have you got a small standalone code which reproduces your problem which I can run?

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> So, it seems that port 21 is closed, is it?

No, that implies that the host "109.110.12.236" is unreachable. This seems to be more of a networking issue and nothing to do with Java as such. How is your other host configured? Is it on the same network? If that IP given to you by your hosting provider?

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Yes which seems pretty logical given the context in which mark() and reset() methods are used i.e. the "going back" to a mark would be only supported if the underlying stream supports either random FP seeks(RandomAccessFile) or a buffered nature (BufferedInputStream).

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

i thought it would work ok too if i use in.next() inside the parseInt()

next() leaves the newline character in the stream which is consumed by the nextLine() call. Use nextLine() call throughout your code and you should be good to go.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Show us the entire IOException stacktrace instead of just the error message. Also, if it works locally, it seems more of a networking issue. Are you able to "ping" to that host? Are you able to "telnet" to that host on the given port(21)?

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Yes for Serializable (Externalizable) and Remote interface. I'm not sure what you mean by "derived from ObjectInput ObjectOutputStream" since object reading/writing is done behind the scenes...

BTW, why not try it out and write a sample server by reading the tutorials posted in one of my previous posts? You'd learn more by doing than just asking...

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

You can have any number/kinds of methods in your RMI server implementation as long as they follow the RMI specification (namely having an interface which extends Remote interface, methods should throw RemoteException, Objects of classes used for communication need to be serializable etc.)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

This is a different error; seems more of a networking issue than a Java one. Are you able to ping that host or telnet to that host for the given port?

ping 192.168.1.3
telnet 192.168.1.3 your-port

There are many reasons why you might get a timeout like bad network configuration, firewalls, overloaded server, bad host or port etc.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

...says the person who ranks 4th. Hah. [j/k ;-)]

AndreRet commented: Thanks for the "stick" +0
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Instead of having a sysout in your catch blocks, put in e.printStackTrace() and post the entire stack trace which comes up on your console (or ide output window). And please post the entire thing, not just the error message.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Read my previous post again; you also need to specify the path of your policy file, not just the system property. It should be:

java -Djava.security.manager -Djava.security.policy="c:/default.policy" RMIClient
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Yeah, why not try it out? Also, just to be sure, enclose the values in quotes and use forward instead of back slashes:

java -Djava.security.policy="c:/my.policy" YourClass
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Oh my god, my eyes, they bleed! :-)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

A few articles you might be interested in:

A few comments:

  • Your use of pseudo code is kind of confusing; I think using a language like Java, Python etc. might be more clear
  • Try using LaTeX for writing down equations or at least write them in [icode]

    [/icode] tags for clarity. The way it is right now, it seems really cluttered.

E.g. in LaTeX, i=2^x looks like [TEX]i=2^x[/TEX]

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

You specify a SecurityManager but don't specify a custom policy file which is what is causing the problem here since the "default" java.policy file which comes with the JRE hasn't got the entry which allows you to "connect" to a socket.

The solution here would be to specify your own policy file by creating a new one and specifying it via the -Djava.security.policy="path/to/policy/file". Read the Java security guide for more details. As a start, you can create a policy file which gives the executing Java process all permissions:

grant { 
    permission java.security.AllPermission;
};

Save this piece of code in a file and name it my.policy. Specify the location to this file when using -D switch in the JVM arguments and you should be good to go.

In case your RMI server would be executing untrusted client code, make sure you create a well-thought out security file for the server to ensure that clients from executing arbitrary unsafe code.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

It seems that you still haven't read the links I posted since the links clearly make no mention of "rmic". Also, when I say complete stack trace, you need to post the "entire stack trace" which you see on your console or IDE window instead of just the "exception message".

Anyways, try running your RMI service on a higher end port like 12345 and see if it still gives the same problem.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Like already mentioned in my previous post, paste the *entire* stack trace instead of just bits and pieces. Also, if you have made any code changes, post them and make sure that the lines numbers in the stack trace match with those of the posted code.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

The exception probably says that a database operation was attempted on a closed connection. Are you using some sort of connection pool? Also, try removing the listeners which initialize quartz and then check if you can issue a simple query to your database in your servlet.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Why does the client only read a single image whereas the server writes out 5 images? Why doesn't the server run in a headless mode i.e. why doesn't it accept the image number from the client or via a configuration rather than popping up a box?

The error probably means that the client closed the connection to the server hence writing out to the "client stream" gives an exception...

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

The format acceptable by the Naming.lookup method is mentioned in the javadocs of the Naming class. For more information on binding a service to a given name and looking it up when writing the client, refer: rmi server tutorial, rmi client tutorial

Follow the instructions mentioned and re-post again if facing problems with the *complete* stack trace.

EDIT: Also, the concept of Skeletons & stubs has been deprecated. This getting started guide creates a simple client and server without using the deprecated rmic (rmi compiler) for creating stubs.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Tip: Try breaking your posts into logical paragraphs and adding additional line breaks for better readability. The way it is written as of now, it seems like a big "wall of text". :-)

Agapelove68 commented: Thank you for bringing that to my attention. Good advise. +0
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

That's an Area 51 link which everyone might not be able to access given that this is the "Community Feedback" forum. :-)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I actually like the idea of your ranking showing up whilst hovering over the avatar. It will give a quick glimpse of a total reputation of the poster, and not just his rep and solved.

But based on the experience with dealing with these kinds of changes, I'm sure someone would comment on the "cluttered" hover box and some might even ask for links in the same. :-)

My other reason for asking about a direct link is because of the time consumption on opening your own page, then selecting the rankings option and then view the rankings. That is like opening 3 pages before you get to what you are looking for. I am sure a lot of posters is going to get annoyed by this, which will eventually result in them not bothered about rankings anyway.

This brings up the question: how much is "just enough" when it comes to presenting data upfront to the user. This is a pretty much involved topic in its own sense (usability I mean) and might require a couple of big changes (e.g. bring fields A, B, C on the profile page to the footer, bring fields X,Y,Z to header etc.).

Now, if I understood the previous posts well enough, it seems that the ranking system is primarily for the newbies, on which I agree.

Not exactly newbies, basically new members who might want to be part of the contributing ecosystem but kind of fail to find the necessary motivation …

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Are you directly serving pages via Tomcat or using some sort of webserver as front end (e.g. Apache web server, Nginx etc.)?

If you are using Apache, use something along the lines of mod_rewrite for Apache. I've never personally used it but heard that it can do wonders when it comes to manipulating URL's. I'm sure something similar exists for Nginx. If you are using a pure servlet front end, you might want to look into the UrlRewriteFilter. Please refer the appropriate documentation and relevant forum for finer configuration details or for help in getting started with the same.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

The reason for having that link on your profile page as opposed to the site "header" is that it presents you with a personalized view of the ranking at Daniweb. It is a metric which is similar to *your* upvoted posts, your post distribution in different forums, your reputation power etc.

A new link can be added at the top but I feel that it is currently at the right place. Another place would to be place it similar to how reputation and solved thread count are shown on hovering over the avatar, but some might argue about the cluttered interface. So yeah... :-)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Um..... if this is a Java question you may want to post it in the Java (not C++) forums.

Please use the "Flag Bad Post" button to help us tackle such things. Making a post saying "it's not the correct forum" might lead to double posting by the OP.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

The "Top Members by Rank" link next to the member count in the left hand corner at the top of the page works for me, though it doesn't give you the same "relative" personalized view as the one given by your profile page.

But then again, since I'm on the first page, it works out well for me.

┐( ̄3 ̄)┌

WASDted commented: helpful answer :) +0