替换JAVA中的JDBC
我想在我的java项目中使用Ormlite,所以我创建了两个bean:
@DatabaseTable(tableName = "worker")
public class Worker {
@DatabaseField(columnName="wo_id" , generatedId=true , id=true)
private Integer woId;
@DatabaseField(columnName="wo_nom")
private String woNom;
}
@DatabaseTable(tableName = "qualification")
public class Qualification {
@DatabaseField(columnName="qu_id" , generatedId=true , id=true)
private Integer quId;
@DatabaseField(columnName="qu_nom")
private String quNom;
}
在创建表时,我发现(也许太晚了?)我需要SQLlite或类似的东西......
是否可以创建和使用数据库我的 Java 项目没有使用 JDBC 或任何其他类似的东西?
I wanted to use Ormlite in my java project so I created two beans :
@DatabaseTable(tableName = "worker")
public class Worker {
@DatabaseField(columnName="wo_id" , generatedId=true , id=true)
private Integer woId;
@DatabaseField(columnName="wo_nom")
private String woNom;
}
@DatabaseTable(tableName = "qualification")
public class Qualification {
@DatabaseField(columnName="qu_id" , generatedId=true , id=true)
private Integer quId;
@DatabaseField(columnName="qu_nom")
private String quNom;
}
When creating the tables, I figured out (too late maybe?) that I needed SQLlite or something like that...
Is it possible to create and use a database from my Java project without using JDBC or anything else of the kind?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
JDBC 是 Java 与任何类型的数据库交互的方式,除非您愿意编写自己的数据库驱动程序。假设您不想这样做,并且您真正需要的是内存中或基于文件的数据库,请使用 H2。它优于 HSQL(它的前身)和 Derby。
JDBC is the way that Java interacts with databases of any kind unless you care to write your own database driver. Assuming you don't want to do that and what you're really looking for is an in-memory or file-based database, use H2. It's superior to both HSQL, which is its predecessor, and Derby.
@RyanStewart 是正确的,如果您正在谈论连接到 SQL 数据库,那么是通过 JDBC 进行的,这就是 Java 与 SQL 数据库(如 H2、Sqlite、MySQL、Postgres、Derby 等)进行通信的方式。所有这些数据库ORMLite 支持类型。
仅供参考,不使用 JDBC 使用 ORMLite 的一种方法是实现后端数据库接口:
这将允许您实现后端。但我怀疑您应该使用 JDBC,但也许此信息对其他人有帮助。
@RyanStewart is correct that if you are talking about connecting to a SQL database, the was to do with is through JDBC which is how Java communicates with SQL databases like H2, Sqlite, MySQL, Postgres, Derby, etc.. All of those database types are supported by ORMLite.
Just for posterity, one way to use ORMLite without JDBC is to implement the backend database interfaces:
This would allow you to implement a backend. But I suspect that you should use JDBC but maybe this information is helpful to others.
内存数据库:http://db.apache.org/derby/
An in memory database : http://db.apache.org/derby/
您可以使用 HSQLDB。
HSQLDB - 100% Java 数据库
运行和使用 Hsqldb
You can use HSQLDB.
HSQLDB - 100% Java Database
Running and Using Hsqldb