Java class in DB

社会主义新天地 提交于 2019-12-25 01:48:16

问题


Can anyone explain why was idea to store Java class in Db? What it is good for? And how to create stored procedure with Java class?

Best regards!


回答1:


Oracle introduced stored procedures into their database in release 8i. The i stood for "internet", as in "internet-ready", which basically was a bit of marketing. But Java Stored Procedures allowed Oracle to extend the range of functionality available in the database queite dramatically, by leveraging the vast amount of Java libraries available. A lot of the new database functionality in Oracle 8i was PL/SQL wrappers of Java libraries, notably the XML stuff.

Significantly Oracle re-wrote a lot of that functionality into native C in Oracle 9, because it ran a lot faster than the wrapped Java stuff. I know, fancy that.

For us, when does it make sense to use Java Stored Procedures? Basically, when there features available in Java which are not available in the native database language. For instance, I have written JSPs to wrapper the ICE Syslog java classes, so my PL/SQL logging routines can write to syslog files. This indicates a very common use case for Java - extending the reach of our database applications into the OS. Perhaps the most common use of a JSP is to write a host command which allows a PL/SQL program to fire an external executable.

I know some developers who write JSPs because they know Java and don't want to learn PL/SQL. This is not good enough for two reason:

  1. It is always better to work with built-ins rather than re-inventing the wheel
  2. As I mentioned already, Java in the database doesn't perform as well as native code.

Of course, if you are wroking on a product which has to run against several different database products, then Java's cross-platform adaptability is very appealing. The different flavours of DBMS are most divergent when it comes to their procedural languages (T-SQL vs PL/SQL, etc) because there is no standard for it, unlike SQL.

If you want to learn about writing JSPs in Oracle, the online documentation is a good place to start. If it turns out you are using a different database rather than Oracle, well I'm sure that product has its own equally fine manual.




回答2:


Not really sure what the question is... the idea was just to do stored-procedure-like oeprations in Java instead of more arcane and unfamiliar stored procedure scripting languages. Here's how it works: http://www.oracle.com/technology/tech/java/jsp/index.html




回答3:


Probably for the benefits listed here.

An example of how to create them you may find here Oracle and Java Stored Procedures.




回答4:


I think the question is about the Object Relational Mapping. You can declaratively describe the rules of how to map Java objects to the relational database tables. If you do, you can save a lot of development time writing JDBC code, tracking object changes, implementing loading strategies etc.

http://en.wikipedia.org/wiki/Object-relational_mapping




回答5:


Sybase ASE is also capable of Java stored procedures, however only Java 1.2 in ASE 15, IIRC. For the benefits - see other anwers.




回答6:


Debuger,

As some of the other posters have also asked, your question is very vague.

Are you referring to:

  1. Java based stored procedures in a database?
  2. Mapping a Java Object into a database table?
  3. Storing the byte code of a Java class in a database table?

For point 1, some databases offer a programming hook to allow you to code your stored procedures & functions using Java and exposing them to the SQL engine

For point 2, there are Object-Relational frameworks which will map a Java object (instance) into relational tables for read-write access. (Example: see Hibernate)

For point 3, You could hypothetically write a ClassLoader that will load classes from a database record containing a BLOB of the class in question.

Hope that helps some.



来源:https://stackoverflow.com/questions/2802135/java-class-in-db

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!