Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @RequestMapping(value="helpgroups/helpsections/{id}" , method = RequestMethod.GET)
- public String listHgHelpSections(@ModelAttribute("helpSection") HelpSection helpSection, HelpGroup helpGroup,@PathVariable("id") Long id, BindingResult bindingResult)
- {
- helpGroup.setId(id);
- //info needed to connect to sql server
- final String dbUserName = "AAISdirectHelpUser";
- final String dbPassword = "Wr6Vaswa";
- final String dbURL = "jdbc:sqlserver://127.0.0.1;database=AAISdirectHelp";
- // sql server connection
- try
- {
- Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
- Connection conn = DriverManager.getConnection(dbURL, dbUserName, dbPassword);
- String sql ="SELECT * FROM config.HelpSection WHERE HelpGroupID = ? ";
- PreparedStatement ps= conn.prepareStatement(sql);
- ps.setLong(1, helpGroup.getId());
- ResultSet results = ps.executeQuery();
- while(results.next())
- {
- helpSection = new HelpSection(results.getString("Name"), results.getLong("HelpSectionID"), results.getString("Description"), results.getLong("HelpGroupID"));
- helpGroup.getHelpSections().add(helpSection);
- }
- catch(SQLException e1)
- {
- e1.printStackTrace();
- }
- catch(ClassNotFoundException e2)
- {
- e2.printStackTrace();
- }
- catch(Exception e3)
- {
- e3.printStackTrace();
- }
- return "redirect:/helpgroups/helpsections/{id}";
- }
- //mapping to insert a new help section record
- @RequestMapping("/helpgroups/helpsections/{helpgroupid}/inserthelpsection")
- public String insertHelpSection(@ModelAttribute("helpSection") HelpSection helpSection,@PathVariable("helpgroupid") long helpGroupID, BindingResult bindingResult)
- {
- final String dbUserName = "AAISdirectHelpUser";
- final String dbPassword = "Wr6Vaswa";
- final String dbURL = "jdbc:sqlserver://127.0.0.1;database=AAISdirectHelp";
- Connection conn = null;
- try
- {
- Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
- conn = DriverManager.getConnection(dbURL, dbUserName, dbPassword);
- String insertSQL ="INSERT INTO config.HelpSection (Name, Description, HelpGroupID,Sequence) VALUES (?,?,?,?)";
- PreparedStatement ps = conn.prepareStatement(insertSQL);
- ps.setString(1, helpSection.getName());
- ps.setString(2, helpSection.getDescription());
- ps.setLong(3, helpGroupID);
- ps.setLong(4, 0);
- ps.executeUpdate();
- }
- catch(SQLException e1)
- {
- e1.printStackTrace();
- }
- catch(ClassNotFoundException e2)
- {
- e2.printStackTrace();
- }
- catch(Exception e3)
- {
- e3.printStackTrace();
- }
- return "redirect:/helpgroups/helpsections/{id}";
- }
- package com.aais.helpguides;
- public class HelpSection
- {
- private long id;
- private long helpGroupID;
- private int sequence;
- private String name;
- private String description;
- //default constructor
- public HelpSection()
- {
- }
- //constructor with specific arguments
- public HelpSection(String name, long id, String description, long helpGroupID)
- {
- this.name = name;
- this.id = id;
- this.description = description;
- this.helpGroupID = helpGroupID;
- }
- public long getHelpGroupID()
- {
- return helpGroupID;
- }
- public void setHelpGroupID(long helpGroupID)
- {
- this.helpGroupID = helpGroupID;
- }
- public long getId()
- {
- return id;
- }
- public void setId(long id)
- {
- this.id = id;
- }
- public int getSequence()
- {
- return sequence;
- }
- public void setSequence(int sequence)
- {
- this.sequence = sequence;
- }
- public String getName()
- {
- return name;
- }
- public void setName(String name)
- {
- this.name = name;
- }
- public String getDescription()
- {
- return description;
- }
- public void setDescription(String description)
- {
- this.description = description;
- }
- }
- <!-- iterate over the arraylist -->
- <c:forEach var="section" items="${helpGroup.helpSections}">
- <tr>
- <td>${section.id}</td>
- <td><a href="helpsections/helpinfo/${section.id}">${section.name}</a></td>
- <td>${section.description}<td>
- </tr>
- </c:forEach>
- </table>
- <hr>
- <h2>Insert Help Section</h2>
- <form:form method="post" action="${id}/inserthelpsection" modelAttribute="helpSection">
- <table style="width:750px">
- <tr>
- <td>Help Section Name:</td>
- <td><form:input type="text" path="name"/></td>
- <td>Description:</td>
- <td><form:input type="text" path="description" /></td>
- <%-- <td>Sequence:</td>
- <td><form:input type="text" path="sequence"/> --%>
- <td><input type="submit" value="Insert"/></td>
- </tr>
- </table>
- </form:form>
- return new ModelAndView("newView", model);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement