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 4 of 4

Thread: SImpeJDBCinsert leads to memory leak

  1. #1
    Member
    Join Date
    Apr 2012
    Posts
    57
    My Mood
    Angelic
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default SImpeJDBCinsert leads to memory leak

    Hello,

    I'm having issues with my code, I'm using simpleJDBCinsert in order to create new entry to mt db. But when I run my code, it freezes.

    Thank you for your help.
     @Override
        public void createMission(Mission c) {
            SimpleJdbcInsert createMiss = new SimpleJdbcInsert(dataSource).withTableName("mission").usingGeneratedKeyColumns("id");
            Map<String, Object> parameters = new HashMap<>(5);
     
            parameters.put("Mission_Name", c.getName());
            parameters.put("Mission_Started", c.getStart());
            parameters.put("Location", c.getLocation());
            parameters.put("Mission_End", c.getEnd());
     
            Number id = createMiss.executeAndReturnKey(parameters);
            c.setId(id.longValue());
        }

    here is my simplejdbc query

       btnAddMission.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
     
                    System.out.print("Enter name of the mission: ");
                    Scanner scan = new Scanner(System.in);
                    String name = scan.nextLine();
     
                    System.out.print("Enter the Date of the mission: ");
                    String date = scan.nextLine();
                    Date start = null;
                    try {
                        start = new SimpleDateFormat("yyyy/MM/dd" ).parse(date);
                    } catch (ParseException e1) {
                        e1.printStackTrace();  //
      }
     
                    System.out.print("Enter the location: ");
                    String location = scan.nextLine();
     
                    System.out.print("Enter the exparation time: ");
                    String end = scan.nextLine();
                   Date endD = null;
                    try {
                        endD = new SimpleDateFormat("yyyy/ MM/dd").parse(end);
                    } catch (ParseException e1) {
                        e1.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
                    }
     
     
                    //Long id, String name, String location,Date start,Date end
                    MissionManagerImpl miss = new MissionManagerImpl();
                    Mission mission = new Mission((long) 0, name, location, start, endD);
     
                    miss.createMission(mission);
                }
            });


  2. #2
    Member coderxx0's Avatar
    Join Date
    Feb 2013
    Location
    England, UK
    Posts
    61
    My Mood
    Cool
    Thanks
    1
    Thanked 2 Times in 2 Posts

    Default Re: SImpeJDBCinsert leads to memory leak

    Quote Originally Posted by justyStepi View Post
    Hello,

    I'm having issues with my code, I'm using simpleJDBCinsert in order to create new entry to mt db. But when I run my code, it freezes.

    Thank you for your help.
     @Override
        public void createMission(Mission c) {
            SimpleJdbcInsert createMiss = new SimpleJdbcInsert(dataSource).withTableName("mission").usingGeneratedKeyColumns("id");
            Map<String, Object> parameters = new HashMap<>(5);
     
            parameters.put("Mission_Name", c.getName());
            parameters.put("Mission_Started", c.getStart());
            parameters.put("Location", c.getLocation());
            parameters.put("Mission_End", c.getEnd());
     
            Number id = createMiss.executeAndReturnKey(parameters);
            c.setId(id.longValue());
        }

    here is my simplejdbc query

       btnAddMission.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
     
                    System.out.print("Enter name of the mission: ");
                    Scanner scan = new Scanner(System.in);
                    String name = scan.nextLine();
     
                    System.out.print("Enter the Date of the mission: ");
                    String date = scan.nextLine();
                    Date start = null;
                    try {
                        start = new SimpleDateFormat("yyyy/MM/dd" ).parse(date);
                    } catch (ParseException e1) {
                        e1.printStackTrace();  //
      }
     
                    System.out.print("Enter the location: ");
                    String location = scan.nextLine();
     
                    System.out.print("Enter the exparation time: ");
                    String end = scan.nextLine();
                   Date endD = null;
                    try {
                        endD = new SimpleDateFormat("yyyy/ MM/dd").parse(end);
                    } catch (ParseException e1) {
                        e1.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
                    }
     
     
                    //Long id, String name, String location,Date start,Date end
                    MissionManagerImpl miss = new MissionManagerImpl();
                    Mission mission = new Mission((long) 0, name, location, start, endD);
     
                    miss.createMission(mission);
                }
            });
    have you tried braking down the code to see were you are getting the error..
    have you tried to compile it????

    please answer the questions above

    --- Update ---



    Also please ask a more specific Question

  3. #3
    Member
    Join Date
    Apr 2012
    Posts
    57
    My Mood
    Angelic
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: SImpeJDBCinsert leads to memory leak

    Hey, there is no error,and I can compile it.

    It happens when I press the btnAddMission. The whole JFrame freezes and I have to kill it with task manager,and then I get Process finished with exit code -805306369.

    it must be coming from th other part of the code when I try to call the method

    --- Update ---

    More specific question, I guess that it would be ... I have a memory leak in one of these parts of my code, and I can't find whats wrong. Can someone find it nd fix it

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: SImpeJDBCinsert leads to memory leak

    It happens when I press the btnAddMission. The whole JFrame freezes and I have to kill it with task manager,and then I get Process finished with exit code -805306369.
    Take a look at that method then. How exactly does it proceed? Step by step: a) its called when a JButton is pressed b) it asks for user input from the command line. At what point does it 'freeze'? Do you input data on the command line? Why are you mixing a GUI in swing with command line input? What makes you think this is even remotely due to a memory leak?

Similar Threads

  1. Replies: 0
    Last Post: April 3rd, 2013, 09:17 PM
  2. Loading file into memory is taking up TOO much memory!
    By mapleleafs89 in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: March 19th, 2013, 10:57 PM
  3. Resource leak: 'in' is never closed..?
    By missm in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 3rd, 2012, 02:01 PM
  4. Properly releasing memory to avoid memory pileup/crash
    By fickletrick in forum What's Wrong With My Code?
    Replies: 6
    Last Post: July 22nd, 2012, 10:09 AM
  5. [SOLVED] Memory usage increasing in while loop - is it a memory leak
    By mds1256 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: July 18th, 2012, 10:06 AM