문제

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.

도움이 되었습니까?

해결책

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...

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top