Skip to main content
August 25, 2010
Question

How to use ColdFusion datasource from JAVA

  • August 25, 2010
  • 1 reply
  • 2370 views

Hello, every one:

I'm trying to figure out the way to connect to database from my java data access class by using ColdFusion configured datasource.

But, I have not get any luck.

Here is my test code: Please help.

//Test1.java
import java.sql.*;

public class Test1
{
        public static void main(String argv[])
        {
                try
                {
                        coldfusion.server.DataSourceService dsr = coldfusion.server.ServiceFactory.getDataSourceService();
                        javax.sql.DataSource ds = dsr.getDatasource("project");  //"project" is a datasource name configured in CF admin
                        Connection con = ds.getConnection();
                        /* if connected, do some thing */
                }
                catch ( Exception e1 )
                {
                        System.out.println(e1.toString());
                }
        }
}

I have got it compiled.

But when run it, I got the folowing error:

"coldfusion.server.ServiceFactory$ServiceNotAvailableException: The '' service is not available"

Any idea ? 

Thanks.

Shiofan

  

This topic has been closed for replies.

1 reply

August 25, 2010

anybody know this?

Thanks.

Inspiring
August 25, 2010

>> "coldfusion.server.ServiceFactory$ServiceNotAvailableException:

>> The '' service is not available"Assuming your syntax is correct

Well .. A) is the CF service running and B) what is the rest of the stack trace message? Do you see anything about "permission denied.." or a licensing exception ..?

August 26, 2010

Thanks for the reply.

I'm runing my code against our developement ColdFusion server. It is up runing.and we should have valid license.

Here is the exception stack trace:

coldfusion.server.ServiceFactory$ServiceNotAvailableException: The '' service is not available.
        at coldfusion.server.ServiceFactory.getDataSourceService(ServiceFactory.java:76)
        at Test1.main(Test1.java:10)

Not much more information, just point to the line:

  coldfusion.server.DataSourceService dsr = coldfusion.server.ServiceFactory.getDataSourceService();