JavaSercer Pages Vector values = new Vector( );

January 28, 2007 on 10:21 am | In Java |

JavaSercer Pages Vector values = new Vector( ); values.addElement(new StringValue(userName)); sqlCommandBean.setSqlValue(sqlValue); sqlCommandBean.setValues(values); Vector rows = sqlCommandBean.executeQuery( ); // Create values for insert/update values.removeAllElements( ); values.addElement(new StringValue(password)); values.addElement(new StringValue(firstName)); values.addElement(new StringValue(lastName)); values.addElement(new StringValue(dept)); values.addElement(new DateValue( new Date(StringFormat.toDate(empDate, “yyyy-MM-dd”).getTime( )))); values.addElement(new StringValue(emailAddr)); values.addElement(new TimestampValue( new Timestamp(System.currentTimeMillis( )))); values.addElement(new StringValue(userName)); if (rows.size( ) == 0) { // New user. Insert StringBuffer sb = new StringBuffer( ); sb.append(”INSERT INTO Employee “). append(”(Password, FirstName, LastName, Dept, “). append(”EmpDate, EmailAddr, ModDate, UserName) “). append(”VALUES(?, ?, ?, ?, ?, ?, ?, ?)”); sqlCommandBean.setSqlValue(sb.toString( )); } else { // Existing user. Update StringBuffer sb = new StringBuffer( ); sb.append(”UPDATE Employee “). append(”SET Password = ?, FirstName = ?, “). append(”LastName = ?, Dept = ?, EmpDate = ?, “). append(”EmailAddr = ?, ModDate = ? “). append(”WHERE UserName = ?”); sqlCommandBean.setSqlValue(sb.toString( )); } sqlCommandBean.executeUpdate( ); } catch (SQLException e) { throw new JspException(”SQL error: ” + e.getMessage( )); } catch (UnsupportedTypeException e) { throw new JspException(”Query result error: ” + e.getMessage( )); } catch (ParseException e) { throw new JspException(”Invalid empDate format: ” + e.getMessage( )); } finally { try { if (conn != null) { conn.close( ); } } catch (SQLException e) { // Ignore } } return EVAL_PAGE; } public void release( ) { dataSourceName = null; super.release( ); } } This tag handler has one property, named dataSource. It’s marked as required in the TLD for the tag, so it will always be set: … saveEmployeeInfo com.mycompany.tags.SaveEmployeeInfoTag empty dataSource true … page 258
Note: If you are looking for inexpensive but high quality provider to host and run your serlvet application check Astra servlet hosting services

No Comments yet

TrackBack URI

Sorry, the comment form is closed at this time.