-
1. Re: Getting a reference to data sources in non JBoss apps
cconway Jan 24, 2003 2:18 PM (in response to mcgee)I apoligize in advance if I am misunderstanding what you are trying to do.
Accessing a database from a command line application is completely different from accessing it via an app server.
From the command line program, you have to load the JDBC driver. Here's an example that loads the microsoft driver, connects to a SQL Server database and executes a query:
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
String url = "jdbc:microsoft:sqlserver://myserver:1433;DatabaseName=mydbname;user=myuserid;password=mypassword";
Connection connection = DriverManager.getConnection(url);
Statement statement = connection.createStatement();
String query = "Select * from mytable";
ResultSet rs = statement.executeQuery(query);
The URL is the same URL that you use in your JBoss datasource configuration.
I hope this helps. -
2. Re: Getting a reference to data sources in non JBoss apps
juhalindfors Jan 26, 2003 4:50 PM (in response to mcgee)Your boss is correct, the JBoss datasources are only bound to the in-VM name space, not the global name space. This means that an EJB deployed to the server can lookup the data source directly, whereas an application running in a different process (such as your command line app) cannot.
So either use JDBC directly from your command line app as the previous poster suggested, or build a server side component (stateless session bean or an MBean) that acts as a "bridge" between your command line app and the JBoss data source.