Mysql 连接服务器上数据库的最佳方法是什么?
我正在开发连接到mySql数据库的JSF项目,例如,我有两种删除元素的方法,如Mysql 连接服务器上数据库的最佳方法是什么?,mysql,web-services,jsf,entitymanager,Mysql,Web Services,Jsf,Entitymanager,我正在开发连接到mySql数据库的JSF项目,例如,我有两种删除元素的方法,如 PeopleClient client = new PeopleClient(); client.remove(p.getId().toString()); //删除人() PeopleClient client = new PeopleClient(); client.remove(p.getId().toString()); 1-使用实体管理器直接访问数据库 ut.begin(); p
PeopleClient client = new PeopleClient();
client.remove(p.getId().toString());
//删除人()
PeopleClient client = new PeopleClient();
client.remove(p.getId().toString());
1-使用实体管理器直接访问数据库
ut.begin();
p = em.merge(p);
em.remove(p);
ut.commit();
PeopleClient client = new PeopleClient();
client.remove(p.getId().toString());
2-使用RESTfulWeb服务访问数据
PeopleClient client = new PeopleClient();
client.remove(p.getId().toString());
有理由的话,哪种方法更好 我认为这取决于你的数据的整体情况
PeopleClient client = new PeopleClient();
client.remove(p.getId().toString());
如果您希望有朝一日围绕您的数据构建更多的应用程序(移动应用程序、web应用程序、客户端应用程序),那么我将使用restfulweb服务。您可以更容易地在其他代码库中利用这一点
PeopleClient client = new PeopleClient();
client.remove(p.getId().toString());
如果您只需要这个应用程序的数据,那么我将使用直接数据库方法
PeopleClient client = new PeopleClient();
client.remove(p.getId().toString());
要记住的一件大事是你有多少网络跳转。REST服务必须直接访问数据库。REST=两次网络旅行(一次从应用程序到REST服务,一次从REST服务到数据库)。数据库=一次网络旅行
PeopleClient client = new PeopleClient();
client.remove(p.getId().toString());