Java&本地数据库 [英] Java & Local Databases

查看:262
本文介绍了Java&本地数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TL DR;想要一些Java帮助连接到真正的本地数据库(无法访问服务器技术),或者如果你可以whip up代码,这将工作。它所要做的就是查询DB(MS Access,虽然可以更改),并输出一个JSON字符串。详情请参阅EDIT2。



编辑:在任何人说JDBC之前;我浏览了教程(开始深入阅读),但大多数似乎面向服务器技术,我无法访问。



EDIT2:看起来最多目前的答案是需要安装某种我不幸的是不能做的(没有提到,所以我道歉)。但是,这是目前正在使用的,我想要一个类似于Java的解决方案,这将使它更多的跨浏览器兼容,而不是只有HTA(链接:



http://db.apache.org/derby/



http://hsqldb.org/



Web层



您还可以嵌入像 Jetty 这样的网络服务器。


Jetty有一个口号不要在Jetty中部署你的
应用程序,在
你的应用程序中部署Jetty。这意味着
作为捆绑
的替代品您的应用程序作为标准WAR到
部署在Jetty中,Jetty是
设计为一个软件组件
可以像任何POJO一样在
Java程序中实例化和使用。


嵌入 Jetty



请注意,还有其他网络服务器你可以使用这种方式。


TL DR; Want some Java help with connecting to a truly local database ( no access to server tech ), or if you can whip up code, that will work. All it has to do is query the DB ( MS Access, although can be changed ), and output a JSON string. See EDIT2 for more specificity.

EDIT: Before anyone says JDBC; I looked through the tutorials ( started reading in depth ), but most of it seems to be geared towards server tech, which I have no access to.

EDIT2: Seems most the answers so far are requiring an installation of some kind which I unfortunately cannot do ( and failed to mention, so I apologize ). However, this is what is currently being used and I would like a solution similar for Java that would make it more cross-browser compatible as opposed to being HTA only (link: https://launchpad.net/accessdb )

Okay, for the long version. I'm trying to make use of a local database to create a desktop style application for work ( and possibly make use of the knowledge for other projects ). The database I can create without a problem ( MS Access 2003, just happens to be quickly available ). Currently I'm using ActiveX scripting to work with the database in a HTML Application (*.HTA file works only with Internet Explorer), I would really like to make this more cross browser ( in the event the company EVER switches to an actual browser ) by using JAVA to access the database, then output the results in JSON to a local variable JavaScript can call and make use of.

Honestly would rather tutorial type information as I want to actually learn why this works so I can later modify it to suit my needs. I have Eclipse installed as well as JDK, and can right small programs in Java, so not completely brain dead ( but not far from :P ). I've been working with JavaScript so I can read quite a bit of Java code as it stands ( not the same syntax since they are not related, but the little I do know of Java I can translate back to JS without problem ).

Anyway, any assistance would be greatly appreciated. I can continue developing with ActiveX ( as I know that works on the system and I'm 99% sure they will continue using Internet Explorer, but, would like some flexibility ).

解决方案

I am not sure I understood your requirements very well, however I did decipher some key points. What I am suggesting will let you deliver a complete working application in a single package (say a JAR) that will not require much (if any) configuration or administration of servers.

Some Required skills:

  • Java programming langauge
  • JDBC, SQL
  • JSP and Servlets (for the Web tier)

I'm trying to make use of a local database to create a desktop style application [...] I Want some Java help with connecting to a truly local database ( no access to server tech )

Datastore

JDBC can be used with any database that has a JDBC driver, which isn't necessarily a database in "network mode", it can be used with embedded databases as well.

Here is an example with Derby in embedded mode:

When an application accesses a Derby database using the Embedded Derby JDBC driver, the Derby engine does not run in a separate process, and there are no separate database processes to start up and shut down. Instead, the Derby database engine runs inside the same Java Virtual Machine (JVM) as the application. So, Derby becomes part of the application just like any other jar file that the application uses. Figure 1 depicts this embedded architecture.

Here are some 100% Java and embeddable databases:

http://www.h2database.com/html/main.html

http://db.apache.org/derby/

http://hsqldb.org/

Web tier

You can also embed a Web server like Jetty.

Jetty has a slogan "Don't deploy your application in Jetty, deploy Jetty in your application". What this means is that as an alternative to bundling your application as a standard WAR to be deployed in Jetty, Jetty is designed to be a software component that can be instantiated and used in a Java program just like any POJO.

Embedding Jetty.

Please note that there are other web servers that you can use this way.

这篇关于Java&本地数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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