daily pastebin goal
45%
SHARE
TWEET

Untitled

a guest Mar 20th, 2017 138 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {
  2.   "timestamp": 1490023621440,
  3.   "status": 500,
  4.   "error": "Internal Server Error",
  5.   "exception": "org.springframework.jdbc.BadSqlGrammarException",
  6.   "message": "PreparedStatementCallback; bad SQL grammar [INSERT INTO user(lastName, firstName, dob, phone, email, password) VALUES (?, ?, ?, ?, ?, ?)]; nested exception is java.sql.SQLSyntaxErrorException: Table 'master_slave.user' doesn't exist",
  7.   "path": "/main"
  8. }
  9.    
  10. spring.datasource.url=jdbc:mysql://${writerendpoint}:${port}/${database.name}
  11. spring.datasource.username=root
  12. spring.datasource.password=root
  13. #spring.datasource.driverClassName=com.mysql.jdbc.driver
  14.  
  15. writerendpoint=localhost
  16. port=3306
  17. database.name=master_slave
  18.  
  19. spring.session.store-type=none
  20.  
  21. # ===============================
  22. # = JPA / HIBERNATE
  23. # ===============================
  24.  
  25. # Specify the DBMS
  26. spring.jpa.database = MYSQL
  27.  
  28. # Show or not log for each sql query
  29. spring.jpa.show-sql = true
  30.  
  31. # Ddl auto must be set to "create" to ensure that Hibernate will run the
  32. # import.sql file at application startup
  33. spring.jpa.generate-ddl=true
  34. spring.jpa.hibernate.ddl-auto = create
  35.  
  36. # SQL dialect for genereting optimized queries
  37. spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect
  38.  
  39. spring.jpa.properties.hibernate.default_schema=master_slave
  40.    
  41. @Entity
  42. @Table(name="user")
  43. public class User {
  44.  
  45.     @Id
  46.     @Column
  47.     @GeneratedValue(strategy=GenerationType.AUTO)
  48.     private int userId;
  49.     @NotEmpty
  50.     @Column
  51.     @Max(value=15)
  52.     private String lastName;
  53.     @NotEmpty
  54.     @Column
  55.     @Max(value=15)
  56.     private String firstName;  
  57.     @NotEmpty
  58.     @Column
  59.     private Date dob;
  60.     @Column
  61.     @Max(value=10)
  62.     private String phone;
  63.     @NotEmpty
  64.     @Column
  65.     @Email
  66.     private String email;
  67.     @NotEmpty
  68.     @Column
  69.     @Min(value=6)
  70.     @Max(value=15)
  71.     private String password;
  72.  
  73. and their getters and setters.
  74.    
  75. @Repository
  76. @Qualifier("mysql")
  77. public class MainDaoImpl implements MainDao {
  78.  
  79.     @Autowired
  80.     private JdbcTemplate jdbcTemplate;
  81.  
  82.     /* (non-Javadoc)
  83.      * @see com.app.masterSlave.dao.RegistrationDao#userRegistration(com.app.masterSlave.model.User)
  84.      */
  85.     @Override
  86.     public void userRegistration(User user) {
  87.         final String sql="INSERT INTO user(lastName, firstName, dob, phone, email, password) VALUES (?, ?, ?, ?, ?, ?)";
  88.         final String lastName=user.getLastName();
  89.         final String firstName=user.getFirstName();
  90.         final Date dob=user.getDob();
  91.         final String phone = user.getPhone();
  92.         final String email = user.getEmail();
  93.         final String password = user.getPassword();
  94. //      BCryptPasswordEncoder encodedPassword = new BCryptPasswordEncoder();            
  95. //      final String password = encodedPassword.encode(user.getPassword());
  96.  
  97.         int success = jdbcTemplate.update(sql, new Object[] {lastName, firstName, dob, phone, email, password});
  98.  
  99.         if(success==0) {
  100.             System.out.println("There was an error while insertion.");
  101.  
  102.         }
  103.         else {
  104.             System.out.println("Row with email: " + email + " inserted successfully.");
  105.  
  106.         }
  107.  
  108.     }
  109. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top