AnsweredAssumed Answered

Accessing sql server database from Building block

Question asked by aoliveira on Apr 21, 2017
Latest reply on Jun 4, 2018 by as0045500

Hi.

I am new here and starting to develop for BB. I am a .net developer so everything is new for me here...

I have a building block created in eclipse for  Blackboard Learn +| Release 3100.0.0-rel.107+401e22b

I'm using Eclipse, Tomcat 9 in my development environment (Eclipse Java EE IDE for Web Developers).

I need to access an sql database to get info (execute SPs).

Installed Microsoft JDBC Driver 6.0 for SQL Server.

Included in my code the access to sql database using some code from the samples supplied on the jdbc driver instalation sample folders:

 

 

// Create a variable for the connection string.

  String connectionUrl = "jdbc:sqlserver://localhost:1433;" +

  "databaseName=Test;user=xxx;password=yyy;";

 

  // Declare the JDBC objects.

  Connection con = null;

  Statement stmt = null;

  ResultSet rs = null;

 

          try {

          // Establish the connection.

          Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

              con = DriverManager.getConnection(connectionUrl);

            

              // Create and execute an SQL statement that returns some data.

              String SQL = "SELECT TOP 10 * FROM Person.Contact";

              stmt = con.createStatement();

              rs = stmt.executeQuery(SQL);

            

              // Iterate through the data in the result set and display it.

              while (rs.next()) {

              System.out.println(rs.getString(4) + " " + rs.getString(6));

              }

          }

Added path to the drivers to the classpath

Copied sqljdbc42.jar to the jre instalation path (...Java\jre\lib\ext) and to the tomcat (...\blackboard\apps\tomcat\lib) as mentioned in some internet posts > both in dev and Quality env. (added also to my javabuild path in eclipse project)

 

When I include the line "Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");" I get the error: "...Could not load class com.microsoft.sqlserver.jdbc.SQLServerDataSource from any of the allowed classloaders:..."

When I don't include it, I get "No suitable driver found for jdbc:sqlserver://localhost:1433;databaseName=Test;user=xxx;password=yyy;"

 

Can someone help? Am I doing it all wrong? Is there a better aproach?

Thanks in advance.

Andreia

Outcomes