Results 1 to 2 of 2
  1. #1
    senti71 is offline Member
    Join Date
    Jul 2011
    Rep Power

    Default [SOLVED] SQL management - prepareStatement fails unexpectedly


    Hi, I'm new here so pleased to meet you all.

    I'm working on a project management software Java based called Activity Manager V0.3. I'm trying to make it evolve from its primary basis to a real projet management system for my company.

    In the original software you can basically create tasks, or subtasks attached to a task, subsubtasks... (and so on iteratively). All levels off tasks have the exact same structure and behaviour except that the root task has no parent task specified.

    I'm trying to implement a new feature, that when you create a task (i.e. a project), certain subtasks are automatically created and attached to it.

    Example :

    > Random project (root task)
    ---> Project Management (automatically created)
    ---> Miscellaneous (automatically created)
    ---> Other subtasks (you'll may to create manually afterwards)

    I designed it in a way that when you create the subtasks automatically, the subtasks won't have the same subtasks automatically created property.

    Exemple : (this won't happen)

    >Random project (root task)
    ---> Project Management (automatically created)
    ------> Project Management (automatically created)
    ---------> Project Management (automatically created)

    Well, theorically, it works, but it fails unexpectedly.

    Here's what the code looks like.

    Java Code:
            DbTransaction tx = null;
    	tx = DbMgr.beginTransaction();
    	DbMgr.updateTask(tx, newTask);
            //The parent task has been created. This is the original code and it works perfectly
            //The updateTask method will be detailed later.
            //Now this is the automatically generated subtask
            Task GestionProjTask = newTask(newTask);
    	GestionProjTask.setNumber(StringHelper.appendint(newTask.getNumber(), 1));
            //This SOP show me everything works fine until this point
            "StringHelper.appendint(newTask.getNumber(), 1)" 
            StringHelper.appendint(newTask.getNumber(), 1)
            //Here's where it fails
    [COLOR="red"]	DbMgr.updateTask(tx, GestionProjTask);[/COLOR]
    	//SOP never reached
    Now, let's see the updateTask method.

    Java Code:
    PreparedStatement pStmt = null;
    	try {
    		Connection con = tx.getConnection();
                    //SOP reached everytime
    		System.out.println("connection instanciated");
                           try {
    pStmt = con.prepareStatement("update task set tsk_path=?, tsk_number=?, tsk_code=?, tsk_name=?, " +
    			"tsk_budget=?, tsk_initial_cons=?, tsk_todo=?, tsk_comment=?, tsk_description=?, tsk_objectifs=?, " +
    			"tsk_methodes=?, tsk_client=?, tsk_contactclient=?, tsk_partenaires=?, tsk_responsableprojet=?, " +
    			"tsk_joursprevus=?, tsk_coutjournee=?, tsk_fraismission=?, tsk_statut=?, tsk_datedebut=?, " +
    			"tsk_datefin=?, tsk_dateao=? where tsk_id=?");
    		catch (SQLException e) {System.out.println("prepareStatement fail");}
                    //Statement reached for the original task creation, but not for the subtask                                     
    //automatically created. However, when I create subtask manually everything works fine.
    		pStmt.setString(1, task.getPath());
                    pStmt.//and so on...
    You see, what pisses me off is the fact that it's a banal SQL statement preparation that is not working. When I had problems with Database structure, it was bugging during the pStmt.setThing phase that allowed me to locate the problem easily. I really don't know where it can come from...

    If you have read it entirely, Good Game.
    If you have any idea of where my problem is could eventually come from, tell me.

    Thanks in advance !
    Last edited by senti71; 07-27-2011 at 12:26 PM. Reason: Problem solved.

  2. #2
    senti71 is offline Member
    Join Date
    Jul 2011
    Rep Power


    Well, the fact of posting it and reading it again entirely made me find the mistake out.

    Actually, all updateTask() calling must be surrounded by transaction opening and closing.

    First, I tried to solve it by putting the endTransaction method at the end of the row but it was not working, because actually the newTask method also opens a transaction (that generates a conflict).

    Thanks for the ones who read it and hope it will serve somebody.

    Cya !

Similar Threads

  1. Replies: 4
    Last Post: 09-13-2010, 05:42 PM
  2. connection fails
    By jrjan in forum Advanced Java
    Replies: 3
    Last Post: 01-10-2009, 01:15 AM
  3. Need help PrepareStatement
    By hungleon88 in forum JDBC
    Replies: 6
    Last Post: 09-21-2008, 10:34 AM
  4. Need help PrepareStatement
    By hungleon88 in forum JDBC
    Replies: 1
    Last Post: 09-18-2008, 12:38 PM
  5. problems with prepareStatement
    By Freddie in forum JDBC
    Replies: 0
    Last Post: 05-31-2007, 06:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts