0

in a new window installation, I have installed NetBeans 12.2 with jdk-8u271-windows-x64 and have tried a lot to connect to SQL server but failed. I have download sqljdbc_9.2.1.0_enu.zip driver from Microsoft site.

Previously i was running the same project for 2 years on the same machine which accidentally i had to reinstalled.

Sample code is as under

import java.io.Serializable;
import java.sql.Connection;
import java.sql.DriverManager;
import javax.enterprise.context.SessionScoped;
import javax.inject.Named;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Administrator
 */
@SessionScoped

@Named("dbc")
public class dbc implements Serializable {
    private String ConnectionSucceeded;

    public dbc () {
        try {

            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            String url="jdbc:sqlserver://localhost:6789;databaseName=master";
            Connection CN = DriverManager.getConnection(url, "sa", "pwd");
            ConnectionSucceeded="Got it";
        } catch (Exception e) {
            ConnectionSucceeded="failure";
        }    
    }

    public String getConnectionSucceeded() {
        return ConnectionSucceeded;
    }

    public void setConnectionSucceeded(String ConnectionSucceeded) {
        this.ConnectionSucceeded = ConnectionSucceeded;
    }
}
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html">
    <h:head>
        <title>Facelet Title</title>
    </h:head>
    <h:body>
        Hello from Facelets
        Connection Status #{dbc.connectionSucceeded}
    </h:body>
</html>

An Error Occurred:
javax.enterprise.inject.CreationException
+ Stack Trace
+ Component Tree
+ Scoped Variables

Furthermore, in services section, Database connection has been successfully built and working but cannot do the same in code.

somebody pls help.

1 Answers1

0

There is no problem in Glass Fish 4.1, basic problem is with Glass fish 5.1. I don't know whether it relates to SQL Server driver or general, but following two corrections/amendments have to be done in Glass Fish Files:

1. java.lang.NoClassDefFoundError: sun/security/ssl/SupportedEllipticCurvesExtension

    Solution : https://stackoverflow.com/questions/49112316/java-lang- 
    noclassdeffounderror-sun-security-ssl-supportedellipticcurvesextensio

    Remove Sun Folder From GlassFish_Server\glassfish\modules\endorsed\grizzly-npn- 
    bootstrap.jar File
2. Glass Fish Application Deployment Error

   resolution source: https://www.youtube.com/watch?v=UWFrylN_Uuk
   i.   GlassFish_Server\glassfish\modules\Console-Common.jar
   ii.  Applications\UploadFrame.jsf
   iii. replace <sun:form id="form"> 

                   with 

        <sun:form id="form" enctype="multipart/form-data">

and Finally Restart the server and every thing will be in operation.

Regards.