Guest User

Untitled

a guest
Mar 27th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.70 KB | None | 0 0
  1. server.port=8181
  2.  
  3. spring.datasource.url = jdbc:mysql://localhost:3306/my_sample_schema
  4. spring.datasource.username = qwerty
  5. spring.datasource.password = qwerty
  6. spring.datasource.driver-class-name=com.mysql.jdbc.Driver
  7. spring.datasource.driverClassName=com.mysql.jdbc.Driver
  8. debug=true
  9.  
  10. package com.example;
  11. ....all imports...
  12.  
  13. @SpringBootApplication
  14. public class Test123Application extends SpringBootServletInitializer {
  15.  
  16. public static void main(String[] args) {
  17. SpringApplication.run(Test123Application.class, args);
  18. }
  19. }
  20.  
  21. package com.example.controller;
  22. ....all imports...
  23.  
  24. @Controller
  25. public class TestController {
  26.  
  27. @RequestMapping(value = "/")
  28. public String demofunction(){
  29. return "dummytemplate";
  30. }
  31.  
  32. @RequestMapping("/default")
  33. public String demofunction2(Model model){
  34. Docrepo docrepo = new Docrepoimpl();
  35. List<Docmaster> listContact = docrepo.list();
  36. model.addAttribute("listContact", listContact);
  37. return "dummytemplate2";
  38. }
  39. }
  40.  
  41. package com.example.repository;
  42. ----all imports---
  43.  
  44. @Configuration
  45. @Repository
  46. public class Docrepoimpl implements Docrepo{
  47.  
  48. @Autowired
  49. private JdbcTemplate jdbcTemplate;
  50.  
  51.  
  52. public void adddoctor(Docmaster doc){
  53.  
  54. String sql = "INSERT INTO docmastertable (docid,name,yoe,speciality,degree,college,hospital,regno)"
  55. + " VALUES (?,?,?,?,?,?,?,?)";
  56. jdbcTemplate.update(sql, doc.getdocid(), doc.getname(),doc.getyoe(), doc.getspeciality(),doc.getdegree(),doc.getcollege(),doc.gethospital(),doc.getregno());
  57. }
  58.  
  59. public List <Docmaster> list(){
  60. String sql = "SELECT * FROM docmastertable";
  61.  
  62. if(jdbcTemplate != null)
  63. System.out.println("jdbc seems ok...");
  64. else
  65. System.out.println("jdbc is null...");
  66.  
  67. List<Docmaster> listContact = jdbcTemplate.query(sql, new RowMapper<Docmaster>() {
  68.  
  69. @Override
  70. public Docmaster mapRow(ResultSet rs, int rowNum) throws SQLException {
  71. Docmaster doc = new Docmaster();
  72. doc.setdocid(rs.getString("docid"));
  73. doc.setname(rs.getString("name"));
  74. doc.setyoe(rs.getInt("yoe"));
  75. doc.setspeciality(rs.getString("speciality"));
  76. doc.setdegree(rs.getString("degree"));
  77. doc.setcollege(rs.getString("college"));
  78. doc.sethospital(rs.getString("hospital"));
  79. doc.setregno(rs.getString("regno"));
  80. return doc;
  81. }
  82. });
  83. return listContact;
  84. }
  85. }
Add Comment
Please, Sign In to add comment