Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- "user": {
- "id": "F3S3I-A3li3",
- "age": "205",
- "comment": "Hello I am a random string"
- }
- }
- public void addToDatabae(String content){
- JSONObject = new JSONObject(content);
- User u = new User();
- u.setJavaID(newUserJSON.getJSONObject("user").getInt("id"));
- u.setName(newUserJSON.getJSONObject("user").getString("age"));
- u.setAge(newUserJSON.getJSONObject("user").getInt("comment"));
- enter code here
- EntityManagerFactory emf = Persistence.createEntityManagerFactory("pu");
- EntityManager em = emf.createEntityManager();
- em.getTransaction().begin();
- em.persist(u);
- em.getTransaction.commit();
- }
- <persistence version="2.1"
- xmlns="http://xmlns.jcp.org/xml/ns/persistence"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
- <persistence-unit name="pu">
- <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
- <properties>
- <property name="openjpa.ConnectionURL" value="jdbc:mysql://localhost:3306/tableEntries?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC"/>
- <property name="openjpa.ConnectionDriverName" value="com.mysql.jdbc.Driver"/>
- <property name="openjpa.ConnectionUserName" value="root"/>
- <property name="openjpa.ConnectionPassword" value="secret"/>
- </properties>
- </persistence-unit>
- </persistence>
Add Comment
Please, Sign In to add comment