5 Replies - 487 Views - Last Post: 07 July 2017 - 11:05 PM

#1 eddyboy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 09-July 14

JSP SQL Server connection

Posted 02 July 2017 - 10:15 AM

Hi,

I have been trying to return data from sql server (not mysql) in a jsp page without success. I was paying attention to the JAR, the import statement, the environment variable but couldn't get it working.

I get the error:"java.lang.ClassNotFoundException: com.microsoft.sqlserver.SQLServerDriver"

This means it must be the CLASSPATH, right?

Can somebody kindly show me JSP code that works showing the class name for the imported jar (jdbc-se2.0.jar) and the import statement/s required please? I tried copying the few examples on intranet without any luck so if somebody has working code on their machine they could use as an example, that would be great.

I am using eclipse oxygen by the way.

Thanks.

Is This A Good Question/Topic? 0
  • +

Replies To: JSP SQL Server connection

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13558
  • View blog
  • Posts: 54,107
  • Joined: 12-June 08

Re: JSP SQL Server connection

Posted 02 July 2017 - 10:20 AM

I'm not clear on what your code looks like, references, version of mssql, etc.. but MS indicates that may be a reference naming issue.

https://blogs.msdn.m...qlserverdriver/
Was This Post Helpful? 0
  • +
  • -

#3 eddyboy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 09-July 14

Re: JSP SQL Server connection

Posted 02 July 2017 - 11:00 AM

Hi,

Thanks for your response. I do not have a syntax issue, I think it is an issue around class name reference hence the error message I mentioned.

It would be nice to see what jar file somebody was using to connect to sql server along with the import statement
e.g. <%@ page import="java.sql.*" %>

and class reference

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


Thanks.
Was This Post Helpful? 0
  • +
  • -

#4 ndc85430  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 612
  • View blog
  • Posts: 2,584
  • Joined: 13-June 14

Re: JSP SQL Server connection

Posted 02 July 2017 - 11:14 AM

Can you also show how you're running the application? Are you including the JAR on the classpath?

Also, apparently JSTL has an <sql> tag that you can use, rather that writing the Java code right there in your templates (see, e.g. this). I assume that writing Java in the JSPs is quite cumbersome, since they're really only meant for the "view" part of your application.
Was This Post Helpful? 0
  • +
  • -

#5 eddyboy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 09-July 14

Re: JSP SQL Server connection

Posted 02 July 2017 - 12:31 PM

I am including the jar filename in classpath

"C:\Users\User\Downloads\Microsoft JDBC Driver 6.0 for SQL Server\sqljdbc_6.0\enu\jre8\sqljdbc42.jar"
Was This Post Helpful? 0
  • +
  • -

#6 ndc85430  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 612
  • View blog
  • Posts: 2,584
  • Joined: 13-June 14

Re: JSP SQL Server connection

Posted 07 July 2017 - 11:05 PM

I think you're going to need to show the code you have. Have you also looked at the link posted by modi123_1 above?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1