Question

I have to run queries (SELECT/INSERT) in MySQL database using Ebean. There are two options that I found in Java - Play framework

1. Connection conn=DB.getConnection();
   Statement st=conn.createStatement();
   ResultSet rs=st.executeQuery("select * from table1");

Using Ebean

 2.Connection conn=DB.getConnection();
    SqlUpdate down=Ebean.createSqlUpdate("insert into table1 (codefile,ADT,AD,TAG) VALUES (7555,'Ebean',0,0)");
    down.execute();

But I want to Map (insert complete array) in MySQL database rather than using the queries above.

Was it helpful?

Solution

as poornerd suggested - you need to create models first with proper fields, then create and object, pseudo code :

MyModel obj = new MyModel();
obj.codefile = 7555;
obj.adt = "Ebean";
obj.ad = 0;
obj.tag = 0;
obj.save()

(of course you can create proper constructors in model(s) as well to shortcut it to:

MyModel obj = new MyModel(7555, "Ebean", 0, 0);
obj.save()

Take a closer look to models of computer-database sample app

Note.: sample you found SqlUpdate down=Ebean.createSqlUpdate... was a demo where it was required to perform 'manual' query, but for common use cases you should go with common Ebean approach...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top