如何使用Scala连接到MySQL数据库? [英] How can I connect to a MySQL database using Scala?

查看:297
本文介绍了如何使用Scala连接到MySQL数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个小项目,我想解析一些数据,然后将其放入数据库中.我没有使用Lift,并且还没有找到一种标准的方法来执行此操作.

我可以自己编写查询,但是我不确定使用什么来实际连接到数据库.

解决方案

您可以使用 JDBC -使Java与数据库对话的标准方法.您需要适当的 MySQL JDBC 驱动程序. Apache DbUtils 提供了一些有关JDBC的实用程序类,将很有用.

如果您希望使用更高级别的API,以消除某些样板,请签出 Spring的JDBC集成.

如果您要使用ORM(对象关系映射),那么休眠是一个不错的选择. /p>

我已经在Scala中成功使用了这三个.

I'm working on a little project where I'd like to parse some data, and then put it into a database. I'm not working with Lift, and I haven't been able to find a standard way to do this.

I'm fine writing the queries myself, but I'm not sure what to use to actually connect to the DB.

解决方案

You can use JDBC - the standard means of getting Java to talk to databases. You'll need the appropriate MySQL JDBC driver. Apache DbUtils provides some utility classes surrounding JDBC and would be useful.

If you want a higher level API which takes some of the boilerplate out, then check out Spring's JDBC integration.

If you want an ORM (object-relational mapping), then Hibernate is a good choice.

I've used all three in Scala with success.

这篇关于如何使用Scala连接到MySQL数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆