Guest User

Untitled

a guest
Oct 15th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. {
  2. "user": {
  3. "id": "F3S3I-A3li3",
  4. "age": "205",
  5. "comment": "Hello I am a random string"
  6. }
  7. }
  8.  
  9. public void addToDatabae(String content){
  10. JSONObject = new JSONObject(content);
  11. User u = new User();
  12. u.setJavaID(newUserJSON.getJSONObject("user").getInt("id"));
  13. u.setName(newUserJSON.getJSONObject("user").getString("age"));
  14. u.setAge(newUserJSON.getJSONObject("user").getInt("comment"));
  15. enter code here
  16.  
  17. EntityManagerFactory emf = Persistence.createEntityManagerFactory("pu");
  18. EntityManager em = emf.createEntityManager();
  19.  
  20. em.getTransaction().begin();
  21. em.persist(u);
  22. em.getTransaction.commit();
  23.  
  24. }
  25.  
  26. <persistence version="2.1"
  27. xmlns="http://xmlns.jcp.org/xml/ns/persistence"
  28. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  29. xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
  30. <persistence-unit name="pu">
  31. <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
  32. <properties>
  33. <property name="openjpa.ConnectionURL" value="jdbc:mysql://localhost:3306/tableEntries?useUnicode=true&amp;useJDBCCompliantTimezoneShift=true&amp;useLegacyDatetimeCode=false&amp;serverTimezone=UTC"/>
  34. <property name="openjpa.ConnectionDriverName" value="com.mysql.jdbc.Driver"/>
  35. <property name="openjpa.ConnectionUserName" value="root"/>
  36. <property name="openjpa.ConnectionPassword" value="secret"/>
  37. </properties>
  38. </persistence-unit>
  39. </persistence>
Add Comment
Please, Sign In to add comment