0

I was trying to run a simple JSP file to retrieve data from Microsoft SQL Server using following simple code:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ page import= "java.sql.* "%>    
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
out.println("Comand completed successfully"+"<br>");
String connString="jdbc:sqlserver://DESKTOP-HTN7DNE\\MSSQLSERVER;"+"databaseName=Hospital_Mmg_System; integratedSecurity=true;";
Connection conn= DriverManager.getConnection(connString);
Statement stmt=conn.createStatement();
String query="Select * From patient";
ResultSet rs=stmt.executeQuery(query);

while(rs.next()) {
    out.println(rs.getString(1)+"  "+rs.getString(2)+"  "+rs.getString(3)+"  "+ rs.getString(4)+"  "+ rs.getString(5)+"  "+ rs.getString(6)+"<br>");
}
%>

I faced that error, then I copied the mssql-jdbc_auth-9.2.1.x64.dll file and pasted in the Java bin folder and it worked.

But then I'm trying to run another JSP file to insert data to the database using the following simple codes:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@page import="java.sql.*,java.util.*"%>

<%
String first_name=request.getParameter("first_name");
String last_name=request.getParameter("last_name");
String city_name=request.getParameter("city_name");
String email=request.getParameter("email");


Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String connString="jdbc:sqlserver://DESKTOP-HTN7DNE\\MSSQLSERVER;"+"databaseName=Test; integratedSecurity=true;";
Connection conn= DriverManager.getConnection(connString);
Statement st=conn.createStatement();

int i=st.executeUpdate("insert into users(first_name,last_name,city_name,email)values('"+first_name+"','"+last_name+"','"+city_name+"','"+email+"')");
out.println("Data is successfully inserted!");
%>

I'm faced with the same error. I have already pasted this mssql-jdbc_auth-9.2.1.x64.dll in the Java bin file, then why this error again? What should I do now?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Mehedi Hassan
  • 11
  • 1
  • 3
  • Will this Stack Overflow Answer Help you? https://stackoverflow.com/a/6087911/15590269 – Sam Joshua Jun 16 '21 at 08:25
  • try this https://stackoverflow.com/questions/6087819/jdbc-sqlserverexception-this-driver-is-not-configured-for-integrated-authentic – Light26 Jul 24 '23 at 00:40

0 Answers0