MySql db connection through JavaScript

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2008 08:31 AM
Hello,
Can i connect to db through javascript in Alfresco?
I need to fetch some data from db, just read from it.. simple "fetch" of 1 field..
If not possible, what are my second options?
Thanks everybody
Can i connect to db through javascript in Alfresco?
I need to fetch some data from db, just read from it.. simple "fetch" of 1 field..
If not possible, what are my second options?
Thanks everybody
Labels:
- Labels:
-
Archive
6 REPLIES 6
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2008 01:03 AM
From 2.1.3 on you can access Java APIs from Javascript - see http://wiki.alfresco.com/wiki/JavaScript_API#Native_Java_API_Access. This would give you access to the JDBC API (or SpringJDBC or Hibernate or whatever) from Javascript, albeit it won't necessarily be easy to do in a production-grade fashion (eg. exception handling can be difficult to do properly in Javascript).
Cheers,
Peter
Cheers,
Peter

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2008 03:55 AM
found this article:
http://peter.michaux.ca/article/3019
Appendix 2: talking with the database from the Rhino shell
I make java file, put it in source, org.alfresco.mysqlconnect; I compile the code..
This should work, but I don't know how to call java function with javascript in alfresco..
Anybody?
thanks
http://peter.michaux.ca/article/3019
Appendix 2: talking with the database from the Rhino shell
I make java file, put it in source, org.alfresco.mysqlconnect; I compile the code..
This should work, but I don't know how to call java function with javascript in alfresco..
Anybody?
thanks
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2008 10:14 AM
http://wiki.alfresco.com/wiki/JavaScript_API#Native_Java_API_Access describes how (in 2.1.3 and beyond) you can access Java APIs from Javascript running within Alfresco.
Cheers,
Peter
Cheers,
Peter

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2008 10:44 AM
found this article:
http://peter.michaux.ca/article/3019
Appendix 2: talking with the database from the Rhino shell
I make java file, put it in source, org.alfresco.mysqlconnect; I compile the code..
This should work, but I don't know how to call java function with javascript in alfresco..
Anybody?
thanks
I've been making some trials with javascript script calling Java. I put jars in lib folder along with other libs in classpath.
You're done, classes are available!
You can use them directly using their full name :
java.io.File
or
var File = java.io.File
function fun(){
var myfile = new File("myFile");…
}
importPackage doesn't work in my configuration (Alfresco-2.1CE) (see: http://forums.alfresco.com/viewtopic.php?t=9711). Upgrading Rhino to 1.7R1 seems to be OK as far as I've tried it.
On the other hand, I don't know how to deal with Java Exceptions and if there are best practices for importing Java classes. I don't know neither how to use the classpath for reading a file from say, extension folder. Answers welcome!
HTH,
Regards,
Stéphane

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2008 07:42 AM
Thank you for your reply!
I already tried to put this java function in web client's lib file..
Maybe my synthax of calling api from js was not correct.. I will try with your example, will let you know.
Thanks again
I already tried to put this java function in web client's lib file..
Maybe my synthax of calling api from js was not correct.. I will try with your example, will let you know.
Thanks again

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2008 06:04 AM
Hi,
updating Rhino with Rhino-1.7R1 allowed me to import java packages in 2.1CE, although importPackage/importClass were disabled. I then realized that it was a big security problem… There has been discussion about allowing javascript use java classes if the script is in the classpath, as noted in the wiki
Could anyone you show an example, or add one in the cookbook?
Thanks a lot,
Best regards,
stebans
updating Rhino with Rhino-1.7R1 allowed me to import java packages in 2.1CE, although importPackage/importClass were disabled. I then realized that it was a big security problem… There has been discussion about allowing javascript use java classes if the script is in the classpath, as noted in the wiki
As of Alfresco 2.1.3, Javascript scripts stored in the classpath can also leverage the Rhino Javascript interpreter's native Java integration facilities (see the Rhino documentation for more details). For security reasons these mechanisms are completely disabled for Javascript scripts that are stored in the repository.So this fonctionality should be available in Alf-Labs3.0, right? What's wrong with this script 'test.js' calling java, with, say, new java.io.File("…") imported in a script?
<import resource="classpath:alfresco/extension/test.js">
which complains that "ReferenceError: "java" is not defined"?Could anyone you show an example, or add one in the cookbook?
Thanks a lot,
Best regards,
stebans
