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.