home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / xampp / xampp-cocoon-addon-1.4.9-installer.exe / updateinfo.js < prev    next >
Encoding:
Text File  |  2004-07-12  |  3.8 KB  |  117 lines

  1. /*
  2. * Copyright 1999-2004 The Apache Software Foundation
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. *     http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. // Step 1 -- Retrieve helper "beans" from the BSF framework
  17.  
  18. scriptaction = bsf.lookupBean( "scriptaction" )
  19. manager      = bsf.lookupBean( "manager" )            
  20. request      = bsf.lookupBean( "request" )
  21. logger       = bsf.lookupBean( "logger" )
  22. actionMap    = bsf.lookupBean( "actionMap" )
  23.  
  24. // Step 2 -- Perform the action
  25.  
  26. logger.debug( "START updateinfo.js" )
  27.  
  28. // Retrieve things from the session and request
  29. // NOTE: they are all of type java.lang.String
  30.  
  31. session       = request.getSession( false )
  32. uwid           = session.getAttribute( "uwid" )
  33. studentname   = request.getParameter( "studentname" )
  34. studentnumber = request.getParameter( "studentnumber" )
  35. current_term  = request.getParameter( "current_term" )
  36. note          = request.getParameter( "note" )
  37.  
  38. logger.debug( "Raw" )
  39. logger.debug( "  uwid           [" + uwid + "]" )
  40. logger.debug( "  studentname    [" + studentname + "]" )
  41. logger.debug( "  studentnumber  [" + studentnumber + "]" )
  42. logger.debug( "  current_term   [" + current_term + "]" )
  43. logger.debug( "  note           [" + note + "]" )
  44.  
  45. // Cook things to make them more palatable to the database
  46.  
  47. note = ( note + "" ) // convert to a JS string
  48. if (note == " ") { note="" }
  49.  
  50. if ( note.length > 255 )
  51. {
  52.    note = note.substring( 0, 255 ); // take the leading 255 characters
  53. }
  54.  
  55. logger.debug( "Cooked" )
  56. logger.debug( "  uwid           [" + uwid + "]" )
  57. logger.debug( "  studentname    [" + studentname + "]" )
  58. logger.debug( "  studentnumber  [" + studentnumber + "]" )
  59. logger.debug( "  current_term   [" + current_term + "]" )
  60. logger.debug( "  note           [" + note + "]" )
  61.  
  62. // We have the choice of declaring things out here and making them explicitly
  63. // null, or we have to use a different comparison in the "finally" block (defined?)
  64.  
  65. dbselector = null
  66. datasource = null
  67. conn = null
  68. updateStatement = null
  69.  
  70. try
  71. {
  72.     dbselector = manager.lookup( scriptaction.DB_CONNECTION )
  73.     datasource = dbselector.select( "ceabplanner" )
  74.     conn = datasource.getConnection()    
  75.     updateStatement = conn.prepareStatement(
  76.         "UPDATE students SET name = ?, current_term = ?, uw_id = ? WHERE uw_userid = ? "
  77.     )
  78.               
  79.     updateStatement.setString( 1, studentname ); 
  80.     updateStatement.setString( 2, current_term ); 
  81.     updateStatement.setString( 3, studentnumber ); 
  82.     updateStatement.setString( 4, uwid ); 
  83.       
  84.     result = updateStatement.executeUpdate()
  85.     logger.debug( "Result #1 [" + result + "]" )
  86.  
  87.     updateStatement = conn.prepareStatement(
  88.         "UPDATE studentnotes SET note = ? WHERE student = ( SELECT id FROM students WHERE uw_userid = ? )"
  89.     )
  90.  
  91.     updateStatement.setString( 1, note ); 
  92.     updateStatement.setString( 2, uwid ); 
  93.  
  94.     result = updateStatement.executeUpdate()
  95.     logger.debug( "Result #2 [" + result + "]" )
  96.  
  97.     conn.commit()
  98.     
  99.     actionMap.put( "scriptaction-continue", "" )
  100.     session.setAttribute( "results", "<SUCCESS>Information Saved at " + Date() + "</SUCCESS>" )
  101.  
  102. }
  103. catch( ex )
  104. {
  105.     logger.debug( "Caught Exception" )
  106.     logger.debug( "  " + ex )
  107. }
  108. finally
  109. {
  110.     if ( null != updateStatement ) { updateStatement.close() }
  111.     if ( null != conn ) { conn.close() }
  112.     if ( null != datasource ) { dbselector.release( datasource ) }
  113.     if ( null != dbselector ) { manager.release( dbselector ) }
  114. }
  115.  
  116. logger.debug( "END updateinfo.js" )
  117.