Advertisement

09.18.2008 at 11:04PM PDT, ID: 23744984
[x]
Attachment Details

JDBC connection to SQL Server 2005 from Java CAPS repository project

[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

6.8
Tags:

Sun, JavaCAPS 6 on NetBeans, NetBeans IDE 6.1, Installed on Windows, Java

I am new to Java CAPS integration work and have done a previous project in version 5.1.3.
For a new project we have deicded to develop in version 6 and have installed NetBeans IDE 6.1 Java CAPS enabled on a Windows server.  There is a SQL server 2005 database installed on the same server.

I am unable to connect to SQL server from a repository project using either:
         Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
        String connectionUrl = "jdbc:sqlserver://serverIP:1433;" +
            "databaseName=*****;user=*****;password=*****;";
        Connection con = DriverManager.getConnection(connectionUrl);
or
       java.sql.DriverManager.registerDriver(new com.microsoft.sqlserver.jdbc.SQLServerDriver());

When I use Class.forName the code compiles (as I would expect) but it fails to actually load the driver - I have a println statement after this line which, when the code runs, never appears in the output.  I catch the error which simply gives me the statement "com.microsoft.sqlserver.jdbc.SQLServerDriver".

If I use java.sql.DriverManager.registerDriver(new com.microsoft.sqlserver.jdbc.SQLServerDriver()); then the code does not compile, I get the following error messages:
ERROR: Class com.microsoft.sqlserver.jdbc.SQLServerDriver cannot be resolved at line 29
ERROR: Method registerDriver(**Unknown Type**) not found in class java.sql.DriverManager at line 29

I have got
import java.sql.*;
import java.lang.*;

And I have downloaded the SQL Server 2005 driver and copied it to: appserver\domains\<ourdomain>\lib\ext

I can connect from the JavaCAPS project if I create a database OTD, but I would prefer to avoid this if at all possible.

If I create a new Java Application project in NetBeans (not JavaCAPS repository based) I can use Class.forName etc with no problems, the connection is successful and a basic select statement returns data to the application from the database.

I assume there must be some way to connect to SQL Server from the JavaCAPS project but I am obviously missing something and nothing I try seems to make any difference.

I have attached the code I am using, as you can see it's very basic, it is taking an input file and transferring the contents to an output file before it attempts the database connection.  I am using the file transfer just as a means of driving the program execution from the Enterprise Manager.

Any help would be greatly appreciated.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
package jf_prj_test;
 
import java.sql.*;
import java.lang.*;
 
public class jcdFileXfer
{
    public com.stc.codegen.logger.Logger logger;
    public com.stc.codegen.alerter.Alerter alerter;
    public com.stc.codegen.util.CollaborationContext collabContext;
    public com.stc.codegen.util.TypeConverter typeConverter;
    public void receive( com.stc.connector.appconn.file.FileTextMessage input, com.stc.connector.appconn.file.FileApplication FileClient_1 )
        throws Throwable
    {
        FileClient_1.setText( input.getText() );
        FileClient_1.write();
        try {
            System.out.println( "inside the try" );
           // java.sql.DriverManager.registerDriver(new com.microsoft.sqlserver.jdbc.SQLServerDriver());
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
          
            System.out.println( "after class for name statement");
            String connectionUrl = "jdbc:microsoft:sqlserver://serverIP:1433;" +
                "databaseName=******;user=******;password=******;";
            Connection con = java.sql.DriverManager.getConnection(connectionUrl);
            System.out.println( "after connection" );
 
            // Statement stmt = conn.createStatement();
            // DatabaseMetaData meta = conn.getMetaData();
            //if (conn != null) {
              ////  System.out.println();
             //   System.out.println( "Successfully connected" );
             //   System.out.println();
                // Meta data
                // System.out.println( "\nDriver Information" );
                // System.out.println( "Driver Name: " + meta.getDriverName() );
                // System.out.println( "Driver Version: " + meta.getDriverVersion() );
                // System.out.println( "\nDatabase Information " );
                // System.out.println( "Database Name: " + meta.getDatabaseProductName() );
                // System.out.println( "Database Version: " + meta.getDatabaseProductVersion() );
           // }
        } catch ( Exception e ) {
            System.out.println( "ERROR: " + e.getMessage() );
        }
    }
 
}
 
 
 
Assisted Solution by manuel_m:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
Assisted Solution by manuel_m:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
Author Comment by JenFen:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
Assisted Solution by manuel_m:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
Author Comment by JenFen:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
Expert Comment by manuel_m:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
Assisted Solution by manuel_m:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
Author Comment by JenFen:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
Assisted Solution by manuel_m:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
Accepted Solution by JenFen:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
20081119-EE-VQP-45 / EE_QW_2_20070628