masijade 1,351 Industrious Poster Team Colleague Featured Poster

My another question is ...

How do we get the modification date of a file.?
I just/only want the modification date.?

i cant use 'ls' cmd, this displays all fields

Please help!

Thanks

The man page for ls and the awk command.

-E           The same as -l, except  displays  time  to  the
                  nanosecond  and  with  one format for all files
                  regardless       of       age:       yyyy-mm-dd
                  hh:mm:ss.nnnnnnnnn (ISO 8601:2000 format).

                  In addition, this option  displays  the  offset
                  from  UTC  in  ISO  8601:2000  standard  format
                  (+hhmm or -hhmm) or no characters if the offset
                  is  indeterminable.  The  offset  reflects  the
                  appropriate standard  or  alternate  offset  in
                  force  at  the  file's displayed date and time,
                  under the current timezone.
ls -E f1.sh | awk '{print $6, $7, $8}'
masijade 1,351 Industrious Poster Team Colleague Featured Poster
touch -m 20091114113000 f1.sh
touch -mt 200911141130.00 f1.sh

Take a closer look at the man page.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Yes it will. Why don't you try showing us what you tried.

P.S. Did you try typing "man touch" first?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Scriptlets alone are a bad idea in a JSP. If you insist on doing this "on the spot", then at least make a bean out of it.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

This is not the sort of thing you do from a JSP page itself. This would be something that should (if part of a webservice) be started in a thread (or a few threads) when the application starts and left running. They should then perform a pooling operation (i.e. every few minutes attempt to connect) and write the statuses in a DB (or flat file) and the JSP should do nothing but show the results.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

So do it the same way for MySQL, just with different strings for the Driver and url.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Well, what is stored in the Map is a String, you cannot simply cast a String to a List. Do you want to create a List from multiple elements in this String, or do you want to simply add this String (and other's like it) to another list? If the second, you, of course, want to use add. If the first, the use split (if applicable) and create an array, instead.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Seems as though it is Strings stored in the map and that the map was declared using generics.

So, why are you trying to use a String as a List?

IOW, what is in the map and what are you trying to do here?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Simply connect and catch the exception. On an exception, it is, seemingly, not running, or not running properly. Use HttpURLConnection and connect to the actual site and you can even check the returned http codes (i.e. 404, 501, etc).

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Okay? And your question is?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Well, text, is also "binary". If what you're reading might contain something that is not strictly plain text, then use a BufferedInputStream (with FileInputStream), rather than reader and convert the text parts to text with new String(byte[]).

masijade 1,351 Industrious Poster Team Colleague Featured Poster

BufferedReader, readLine, a counter, and String's split.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Add a System.out.println(System.getProperty("user.dir")) in there.

Otherwise use the search function for the OS.

But, the best way is to provide the full path to the file from the beginning. Why simply deal with defaults that can change due to configuration and/or operating parameters when you can control the operation.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

The MySQL documentation shows you which class, at the very beginning of the page I linked to, and the tutorials (and the MySQL docs) show you how to use it. Read those.

Edit: Besides, why would you be loading a postgresql Driver (jar) when it is mysql (according to your title) that you want to connect to?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

You don't load the jar, you load the Driver class and include the jar on the classpath. See the Tutorial and the MySQL manual for MySQL specific examples

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Configure the ssh to use private keys.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

A bare number that starts with zero is an octal number. And octal numbers cannot include either an 8 or a 9. Remove those zeros.

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

By adding the xlint option shown in the warning to the javac command (how you do this with any IDE you might be using depends on the IDE, read its manual). In any case, as I said, that depended on what getSynonyms returned. Your problem, if you want this warning to go away, goes much deeper. See http://java.sun.com/docs/books/tutorial/extra/generics/index.html.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

It's because you're not using generics. Also, if you look at the compiler message it is a warning, and, in this case, I believe you could ignore it. However, since you are doing all your work with Strings, then, currently, every where in your code where you currently have List (and I do mean everywhere), change it to List<String> .

Edit: Then again, that also depends on this "word" instance and what it's "getSynonyms" returns.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Take a close look at my previous post.

The first code block is your code, the second code block is modifications to that code.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Where would I place this? while (!phrase.equals("quit")) { If I do it before

length = phrase.length();

it won't run because I haven't initialized "phrase".

Well, think about that a bit.

...
        String phrase; // a string of characters
        ...
        // Read in a string and find its length
        System.out.print ("Enter a sentence or phrase: ");
        ...
        System.out.println ();
    }
...
        String phrase = ""; // a string of characters
        ...
        while (!phrase.equals("quit")) {
            // Read in a string and find its length
            System.out.print ("Enter a sentence or phrase: ");
            ...
            System.out.println ();
        }
    }
masijade 1,351 Industrious Poster Team Colleague Featured Poster

Wrap the thing from that point on in a while (!phrase.equals("quit")) { loop.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

You are calling the ethod without any arguments, but the method is designed to take an int and a double, so give it an int and a double.

pwk064 commented: Great help - Thanks! +0
masijade 1,351 Industrious Poster Team Colleague Featured Poster

That information seems to encapsulate a session, so Google around a bit and find out how to maintain a session using HttpURLConnection.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

The browser is not "resolving" anything. The site is "redirecting".

So, are you using URLConnection or HttpURLConnection? HttpURLConnection will "follow" redirects, by default, URLConnection, won't.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Change this

usbThread thread = new usbThread();

    public detectUSB() {
        initComponents();

        thread.start();
        

        final JLabel label = lbl_status;
        final String text = thread.getThreadStatus();

        SwingUtilities.invokeLater(
                new Runnable() {
                    public void run() {
                        label.setText(text);
                        label.validate();
                        label.repaint();
                    }
                }
            );
    }

to this

public detectUSB() {
        initComponents();
    }

and change this

public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new detectUSB().setVisible(true);
            }
        });
    }

to this

public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new detectUSB().setVisible(true);
            }
        });
        new usbThread(lbl_status).start();
    }

and change this

public class usbThread extends Thread{
    public String status=".....";
    usbThread()
    {
      
    }

    String getThreadStatus()
    { 
      return this.status;
    }

    @Override
    public void run() {
        ....
        this.status="FindDrive: waiting for devices...";
            ....
                this.status="Drive "+letters[i]+" has been plugged in";
            else
                this.status="Drive "+letters[i]+" has been unplugged";
                ....
            }
            try { Thread.sleep(100); }
            catch (InterruptedException e) { /* do nothing */ }
        }
    }

to this

public class usbThread extends Thread{
    private String status = ".....";
    private JLabel label;
    usbThread(JLabel label) {
        this.label = label;
    }

    private void postStatus() {
        SwingUtilities.invokeLater(
                new Runnable() {
                    public void run() {
                        label.setText(status);
                        label.validate();
                        label.repaint();
                    }
                }
            );
    }

    @Override
    public void run() {
        ....
        this.status="FindDrive: waiting for devices...";
        postStatus();
            ....
                this.status="Drive "+letters[i]+" has been plugged in";
            else
                this.status="Drive "+letters[i]+" has been unplugged";
                ....
            }
            postStatus();
            try { Thread.sleep(100); }
            catch (InterruptedException e) { /* do nothing */ }
        }
    }
majestic0110 commented: Patience of a Saint! +3
masijade 1,351 Industrious Poster Team Colleague Featured Poster

E.G.

class Checker extends java.util.TimerTask {
  private JLabel label;
  Checker(JLabel label) {
    this.label = label;
  }
  public void run() {
    //check the drives
    final String text = <status>;
    // call invokeLater
  }
}

public class myApp {
  public static JLabel createAndStartGui() {
    JLabel sLabel = new JLabel();
    // create the GUI, set it visible using the above reference
    return sLabel;
  }
  public static void main(String args) {
    JLabel l = createAndStartGui();
    java.util.Timer t = new java.util.Timer(true);  // start as Daemon
    TimerTask tt = new Checker(l);
    t.scheduleAtFixedRate(tt, 0, 100);  // do you really need to check 10 times per second
  }
}
masijade 1,351 Industrious Poster Team Colleague Featured Poster

Because I never said to put the entire thing into "invokeLater". InvokeLater should be used entirely as, and contain nothing more, than shown there. The rest of that should be running in another thread that is started alongside the rest of the application and simply given a reference to the label that it is to update so that it can invoke it in the call to SwingUtilities.

I assume you are starting a GUI out of your main method? If so, do that and keep a reference to this "status label", then start another thread with this stuff in it, passing this "status label" in the constructor, and at the spot where the label is to be updated, call invokeLater.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Then normal swing standalone app.

A preparedstatement, its setString method, and the textfields getText method.

That should get you started.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

A mistake that is completely self correctable

final JLabel label = <reference to the label>;
final String text = <text to change to>;
SwingUtilities.invokeLater(
        new Runnable() {
            public void run() {
                label.setText(text);
                label.validate();
                label.repaint();
            }
        }
    );
masijade 1,351 Industrious Poster Team Colleague Featured Poster

MS Access is file based (i.e. no remote connections, local file access needed) and Applets do not have access to the local file system. A complete redesign is in order.

Sorry, of course a complete redesign is not in order, but you do need to change DBs.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

I think that you can write a server/client solution to get it to work. The client connects to the server which returns the content of the database. I did something like that when I needed my applet to read from a database, but I don't remember all the details.

An applet has no problems connecting to a DB, as long as the DB exists on the same server as the machine that served the page, and the DB is a client/server DB and not MS Access.

Of course you can build your own client/server protocol and connection to enable connection to MS Access, but why? Why pay the hefty license and software costs only to have to build your own (possibly buggy) access routines in order to be able to even use it when there are a plethora of free client/server DBs out there, and most of them are better than MS Access in the first place.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

I need more details. I don't understand what you are actualy doing. The best method would be to make a JTable in which you can see your database table records. Then you can go further. I mean how can you modify something if you can't see what row u actualy modify? (I'm guessing)

Under normal circumstances, how is he to access an MS Access DB from an Applet? It is the pinnacle of arrogance to suggest that the clients should modify their security settings for your app.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

I have a background operation which runs infinitely. I want to set JLabel's text from that thread as it would be the status of the operations in that thread or the progress?

final JLabel label = <reference to the label>;
final String text = <text to change to>;
SwingUtilities.invokeLater(
        new Runnable() {
            label.setText(text);
            label.validate();
            label.repaint();
        }
    );

Did I miss something in the description?

Yes, you missed stating what you wanted to do. As I said "access a component" means, essentially, nothing. It is what you want to do with it that makes a difference.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

MS Access is file based (i.e. no remote connections, local file access needed) and Applets do not have access to the local file system. A complete redesign is in order.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

What are you trying to do with the component. "Access a component" means literally nothing.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Each package has it's own directory (in the normal state of affairs, there are other ways of doing it, but we won't get into those).

I.E. Hypothetical, your source code is under
/my/source
and your compiled code is under
/my/classes
then for the package
thisIs.myPackage
and the class
DontYouLikeIt
the java file should be located at
/my/source/thisIs/myPackage/DontYouLikeIt.java
and the class file should be located at
/my/classes/thisIs/myPackage/DontYouLikeIt.class

So, hopefully those "5 programs" all have the same package and not just "a pacakge".

Now, what exactly, is your problem?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

I give up. You make a change, then later claim that you don't where the change is to be made, then you make another change, that is the counter-point to the first change, with expected results, and wonder why it goes wrong.

All I can say now is, look at your code and balance your braces. for every '{' there should be a '}'. And indent your code properly. As it is now it is very hard to be read clearly.

masijade 1,351 Industrious Poster Team Colleague Featured Poster
cmd /c <command>

See http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

And read it completely and thoroughly, although I can't imagine why you would really want to do all this.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Redesign that "insertdetails" thing. You should not be cobbling together SQL statements like this. It is far too error-prone and an extreme security risk. You have no idea how easy it is to perform an SQL Injection attack like that.

Also, is "setVisible(false);" suppossed to be outside of the method? It is, in the code you posted, which would make this utterly uncompilable.

If, in the "real" code, it is inside the method, I would say that is causing your application to exit (especially if your default close operation is EXIT_ON_CLOSE), or simply hiding it otherwise, regardless of what else happens in that method.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Also, closing a JOptionPane definately should not cause the entire application to close. What does the rest of the method where this statement resides look like?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

And what about the rest of the post?

masijade 1,351 Industrious Poster Team Colleague Featured Poster

What exception, and your problem could possibly be solved by using the "short-circuit" or "||" instead of "|", because that way the second half of that if statement won't even be evaluated if the first half is false. Currently, they are both being evaluated regardless of whether the first is false or not. Also, does not "getText()" return a String? Normally that type of method will, so I don't understand the "toString()" call after that.

Also, what is the rest of the statement after the "|", as the forum seems to have let it run of the end of the window so I can't see it (after the toString call).

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Around this

for (int i = 0; i < numbers.length; i++){
  sum += numbers[i];
  float average = sum / TOTAL_NUMBERS;
}

either move the '}' above the average calculation (which is better IMHO) or remove both the '{' and the '}'.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

You forgot the '{' after the for statement on the block before this point.

masijade 1,351 Industrious Poster Team Colleague Featured Poster
String pic = rs.getString("pincode");

not

String pic = rs.getString(pincode);

Also, use a preparedStatement, cobbling a statement together using String concatenation like you've done is just begging for trouble. Maybe only as innocent as a mistyped user input string that causes the SQL to fail with a syxntax error, or as damaging as an intentional SQL Injection attack.

Edit: And this

if(pic=="pincode")

is probably backwards, too.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

Did you read the API docs for ArrayList, yet? I'll take that as a no.

KimJack commented: Very rude individual +0
masijade 1,351 Industrious Poster Team Colleague Featured Poster

Okay, and your question is?

If you read the API docs for ArrayList you will find a method for retreiving an Object at a specific index. Use it.

masijade 1,351 Industrious Poster Team Colleague Featured Poster

The second option is better as "\n" is platform specific and is not always guaranteed to get the effect you wanted.