Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: MySQL Quit while java application is running

  1. #1
    Junior Member
    Join Date
    Dec 2011
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default MySQL Quit while java application is running

    I have a java app that takes data from a .csv file and put it on my MySQL database. The application has been freezing at random times during the running of the application. At first I though my code might be stuck in the while loop I had but then I though this wouldn't account for the randomness, consisting the same set of data is used each time.

    I'm now pretty sure it's the connection to MySQL. I ran wireshark and see my client PC, running the java code sends a MySQL '59 Request Quit' to the mysql server.

    Anyone have any experience of this problem?


  2. #2
    Junior Member
    Join Date
    Dec 2011
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: MySQL Quit while java application is running

    I've run this a few times now and getting different outcomes, here's the code that crashes (occasionally)


    String cmd = "cmd /c type C:\\Data\\" + x + "\\*.csv";
              String line;
     
              try {
                Process p = Runtime.getRuntime().exec(cmd);
                BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
                System.out.println("Processing " + x + " .csv data");
     
                while ((line = input.readLine()) != null) {
                    // capture output in cdata array
                    if (!"".equals(line)){
                    cdata.add(line);
                    }
                    System.out.println("'"+line+"'");
                    if("\n".equals(line) || "".equals(line)) break;
                }
                input.close();
                System.out.println("Complete Processing of " + x + " .csv data");

    runs the type command in dos and captures each line of the output to an ArrayList. It's rather a big output put there seems to be plently of memory in my PC ford the job, looking at the task manager.

    Any ideas on why this would seemingly stop running? when a crah occurs the 'System.out.println("Complete Processing of " + x + " .csv data")' code doesn't get run, but I can't imagine it's still in the loop because it should at least print a new line like '' at each iteration i.e. System.out.println("'"+line+"'");

  3. #3
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Location
    Tavistock, UK
    Posts
    637
    Thanks
    5
    Thanked 103 Times in 93 Posts

    Default Re: MySQL Quit while java application is running

    Put your code in a file by itself as the body of the main() method and *don't* try-catch exceptions - your main() method should be:

    public static void main(String[] args) throws Exception

    You may well be running out of memory, but let's get a stack trace first.

  4. #4
    Junior Member
    Join Date
    Dec 2011
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: MySQL Quit while java application is running

    Quote Originally Posted by Sean4u View Post
    Put your code in a file by itself as the body of the main() method and *don't* try-catch exceptions - your main() method should be:

    public static void main(String[] args) throws Exception

    You may well be running out of memory, but let's get a stack trace first.
    Hey that's cool we're neighbors, also in Oxford. I made a new class (below). Runs with no exceptions

    public class TestClass {
        public static void main(String[] args) throws Exception{
     
            ArrayList cdata = new ArrayList();
     
            String x = "AAA";
     
              String cmd = "cmd /c type C:\\Data\\" + x + "\\*.csv";
              String line;
     
     
                Process p = Runtime.getRuntime().exec(cmd);
                BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
                System.out.println("Processing " + x + " .csv data");
     
                while ((line = input.readLine()) != null) {
                    // capture output in cdata array
                    if (!"".equals(line)){
                    cdata.add(line);
                    }
                    System.out.println("'"+line+"'");
                    if("\n".equals(line) || "".equals(line)) break;
                }
                input.close();
                System.out.println("end of code");
     
        }
     
     
    }

  5. #5
    Junior Member
    Join Date
    Dec 2011
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: MySQL Quit while java application is running

    Ah, just tried it on the second directory in the group and it freezes,

    third directory runs okay

  6. #6
    Junior Member
    Join Date
    Dec 2011
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: MySQL Quit while java application is running

    Just having a better look at where it's failing. within given directory there is multiple csv file, and i'm using a wildcard to type them all, it seem to randomly fail while going from one file to the next. Here's a sample output

    WDP.BBB,02-Feb-2012,38.44,39.17,38.23,38.85,15871
    WEB.BBB,02-Feb-2012,42.1,42.3,42.1,42.3,286
    WEHB.BBB,02-Feb-2012,69.49,69.49,69,69.2,325
    ZENT.BBB,02-Feb-2012,0.31,0.31,0.31,0.31,350
    ZTS.BBB,02-Feb-2012,15.76,15.95,15.69,15.71,1909

    C:\Data\BBB\BBB_20120203.csv


    ABI.BBB,03-Feb-2012,47.7,48.865,47.425,48.86,1613073
    ABIS.BBB,03-Feb-2012,0.002,0.002,0.002,0.002,312400


    So it would fail at "ZTS.BBB,02-Feb-2012,15.76,15.95,15.69,15.71,1909", maybe this is the problem, i'll look at type command options to give a cleaner output before I try anything in my java code

  7. #7
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Location
    Tavistock, UK
    Posts
    637
    Thanks
    5
    Thanked 103 Times in 93 Posts

    Default Re: MySQL Quit while java application is running

    Quote Originally Posted by aueddonline View Post
    before I try anything in my java code
    Your java code is a bit unusual. For a job like this I would usually use File.listFiles(FileFilter) and use the BufferedReader on each File in turn - I don't understand why you use a Process to do that. Does your code currently run to completion, or is it still pausing? Do you really need to use that ArrayList, or could you do something useful a line-at-a-time in your main loop?

Similar Threads

  1. THE APPLICATION HAS UNEXPECTEDLY QUIT
    By ipam in forum Java ME (Mobile Edition)
    Replies: 3
    Last Post: January 13th, 2012, 02:16 AM
  2. Problem Running J2EE Application - JRE Version Error
    By rameshiit19 in forum Java IDEs
    Replies: 3
    Last Post: November 28th, 2011, 07:12 AM
  3. getting NPException while running my struts first application using tomcat
    By rafishaik999 in forum JavaServer Pages: JSP & JSTL
    Replies: 1
    Last Post: September 19th, 2011, 05:56 AM
  4. Shortcut executed or in-background running Java application
    By xixixao in forum Java Theory & Questions
    Replies: 2
    Last Post: April 22nd, 2011, 04:33 AM
  5. How to make a program quit?
    By copelandtml in forum Loops & Control Statements
    Replies: 6
    Last Post: February 16th, 2011, 01:10 AM