HI folks!!
I'm using JBoss 4.0.2, Eclipse 3.1 and MS SQL Server2000.
I wrote a simple session bean.
Know I want some kind of interaction with database.

To configure JBoss with MSSQL datasource I made the following:
1.  Start MS SQL Server with sql authentication 'sa'
Create a database named Jboss
2. Copy the jar files from JDBC driver (msutil, msbase, mssqlserver) and put 
them in \server\default\lib
3. Copy mssql-ds.xml from \docs\examples\jca\ and put in 
\server\default\deploy. 
Modify
<?xml version="1.0" encoding="UTF-8"?>
...


  <local-tx-datasource>
...
    
<!-- Claudia -->
    <user-name>sa</user-name>
    
<!-- Claudia -->
...
3. Restart JBoss.
In JMX Console, at jboss.jdbc it was added datasource=MSSQLDS.service=metadata

4. In folder \server\default\conf\standardjaws.xml i configured

<?xml version="1.0" encoding="UTF-8"?>
...


<!-- Claudia -->
   java:/MSSQLDS
   <type-mapping>MS SQLSERVER2000</type-mapping>
<!-- Claudia -->
...
5. In folder \server\default\conf\standardjbosscmp-jdbc.xml i configured

<?xml version="1.0" encoding="UTF-8"?>
...

<jbosscmp-jdbc>

   
<!-- Claudia -->
        java:/MSSQLDS
        <datasource-mapping>MS SQLSERVER2000</datasource-mapping>
<!-- Claudia -->
...
6. In folder \server\default\conf\login-config.xml i configured

...

<!-- Claudia -->
  <application-policy name = "MSSQLDbRealm">
       
          <login-module code = 
"org.jboss.resource.security.ConfiguredIdentityLoginModule"
             flag = "required">
<module-option name="principal">sa</module-option>
                <module-option name="userName">sa</module-option>
                <module-option name="password"></module-option>
                <module-option 
name="managedConnectionFactoryName">jboss.jca:service=LocalTxCM,name=MSSQLDS</module-option>
          
                </login-module>
       
    </application-policy>
<!-- Claudia -->

And know what i do?

Before I start using eclipse and jboss, i had a class named Connect and when i 
run it and could see the databases in my sql server. Can I use these code?? 
HOW??? Inside my session bean??

import java.*;

public class Connect{
     private java.sql.Connection  con = null;
     private final String url = "jdbc:microsoft:sqlserver://";
     private final String serverName= "FRC-GIIT-CIRKUS";
     private final String portNumber = "850";
     private final String databaseName= "pubs";
     private final String userName = "sa";
     private final String password = "";
     // Informs the driver to use server a side-cursor,
     // which permits more than one active statement
     // on a connection.
     private final String selectMethod = "cursor";

     // Constructor
     public Connect(){}

     private String getConnectionUrl(){
          return 
url+serverName+":"+portNumber+";databaseName="+databaseName+";selectMethod="+selectMethod+";";
     }

     private java.sql.Connection getConnection(){
          try{
               Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
               con = 
java.sql.DriverManager.getConnection(getConnectionUrl(),userName,password);
               if(con!=null) System.out.println("Connection Successful!");
          }catch(Exception e){
               e.printStackTrace();
               System.out.println("Error Trace in getConnection() : " + 
e.getMessage());
         }
          return con;
      }

     /*
          Display the driver properties, database details
     */

     public void displayDbProperties(){
          java.sql.DatabaseMetaData dm = null;
          java.sql.ResultSet rs = null;
          try{
               con= this.getConnection();
               if(con!=null){
                    dm = con.getMetaData();
                    System.out.println("Driver Information");
                    System.out.println("\tDriver Name: "+ dm.getDriverName());
                    System.out.println("\tDriver Version: "+ 
dm.getDriverVersion ());
                    System.out.println("\nDatabase Information ");
                    System.out.println("\tDatabase Name: "+ 
dm.getDatabaseProductName());
                    System.out.println("\tDatabase Version: "+ 
dm.getDatabaseProductVersion());
                    System.out.println("Avalilable Catalogs ");
                    rs = dm.getCatalogs();
                    while(rs.next()){
                         System.out.println("\tcatalog: "+ rs.getString(1));
                    }
                    rs.close();
                    rs = null;
                    closeConnection();
               }else System.out.println("Error: No active Connection");
          }catch(Exception e){
               e.printStackTrace();
          }
          dm=null;
     }

     private void closeConnection(){
          try{
               if(con!=null)
                    con.close();
               con=null;
          }catch(Exception e){
               e.printStackTrace();
          }
     }
 
        public static void main(String[] args) throws Exception
       {
          Connect myDbTest = new Connect();
          myDbTest.displayDbProperties();
       }   
        
}

Please help me because i'm stuck almost 2 weeks .... :(

Thanks Claudia

View the original post : 
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3890368#3890368

Reply to the post : 
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=3890368


-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
JBoss-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to