java - need code piece to connect to ms sql server 2005

are there any codpieces/mehtods that will let me connect to ms sql server 2005 and a query statement tp:

1) select data from table and populate a session varaible
2) update a table with a session varaible
LVL 10
Who is Participating?

Improve company productivity with a Business Account.Sign Up


this is where you download the driver
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

GlobaLevelProgrammerAuthor Commented:
So I am runnIng my JSP's thru apache on windows OS with ms SQL server 2005 back end, is that a problem? All one server
No I don't think it is a problem -  I guess you are also runnning Tomcat that drives your JSP - you need to make sure that you have the driver jar avialable
in the classpath - I guess it should be wirthin WEB-INF/lib fiolder

Well, after you select data form table with JDBC, you can
set attributes of your session something like that:

HttpSession session = request.getSession(true);

ResultSet rs = statement.executeQuery("select filed1, flied2, field3 from table_name");
String s0 = rs.getString(1);
String s1 = rs.getString(2);
String s2 = rs.getString(3);

session.setAttribute("name1", s0);
session.setAttribute("name2", s1);
session.setAttribute("name3", s2);

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.