开发者

Replace JDBC in JAVA

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 {

    @DatabaseFi开发者_StackOverflow中文版eld(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?


without using JDBC or anything else of the kind

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

Is it possible to create and use a database from my Java project without using JDBC or anything else of the kind?

Just for posterity, one way to use ORMLite without JDBC is to implement the backend database interfaces:

  • ConnectionSource
  • DatabaseConnection
  • CompiledStatement
  • DatabaseResults

This would allow you to implement a backend. But I suspect that you should use JDBC but maybe this information is helpful to others.


An in memory database : http://db.apache.org/derby/


You can use HSQLDB.

HSQLDB - 100% Java Database

Running and Using Hsqldb

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜