Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Problem in MS SQL Connection Using JSP

Posted on 2006-11-16
6
Medium Priority
?
1,694 Views
Last Modified: 2012-08-14
Helo,

I tried to connect to MS SQL using JSP and JTDS driver. I got the following errors:

[ErrorMessage-START]
An error occurred at line: 4 in the jsp file: /search2.jsp
Generated servlet error:
ds cannot be resolved
..
..
con cannot be resolved
..
stm cannot be resolved
..
result cannot be resolved
..
e cannot be resolved
..
..
[ErrorMessage-END]

Below are all the related files:
1. search.jsp (in C:\apache-tomcat\webapps\leone\)
2. context.xml (in C:\apache-tomcat\conf\Catalina\localhost\)

search.jsp:
********
<%@ page import="java.text.*,javax.sql.*,javax.naming.*, com.syslore.multicolumn.*" %>
<html>
<body>
<%
try {
Context context = new InitialContext();
Context envCtx = (Context) context.lookup("java:comp/env");
ds = (DataSource)envCtx.lookup("jdbc/SQLServer");
if (ds != null) {
  con = ds.getConnection();
  stm = con.createStatement();
  result = stm.executeQuery("SELECT * FROM Employees");
  }//if
}

catch (NamingException ex) {
  ex.printStackTrace();
} catch (SQLException e) {
  e.printStackTrace();
}//try
%>
</body>
</html>

context.xml:
*********
<Context path="/TesteSQLServer" docBase="TesteSQLServer" debug="5" reloadable="true">
  <Resource name="jdbc/SQLServer"
    auth="Container"
    type="javax.sql.DataSource"
    maxActive="10"
    maxIdle="1"
    maxWait="10000"
    username="26226255"
    password="tt"
    driverClassName="net.sourceforge.jtds.jdbc.Driver"
    url="jdbc:jtds:sqlserver://XX.XX.XX.XX/ControleOper_DES" />
</Context>

Anyone has idea of how to fix the error?

Thanks.
0
Comment
Question by:SWB-Consulting
6 Comments
 
LVL 10

Accepted Solution

by:
jaggernat earned 1200 total points
ID: 17962569
Replace

con = ds.getConnection();
stm = con.createStatement();
result = stm.executeQuery("SELECT * FROM Employees");

with

Connection con = ds.getConnection();
Statement stm = con.createStatement();
ResultSet  result = stm.executeQuery("SELECT * FROM Employees");
0
 

Author Comment

by:SWB-Consulting
ID: 17962674
After I added the above (as you recommended) below is the error message:

ds cannot be resolved
Connection cannot be resolved to a type
Statement cannot be resolved to a type
SQLException cannot be resolved to a type
e cannot be resolved

But then I replace
ds = (DataSource)envCtx.lookup("jdbc/SQLServer");
with
DataSource ds = (DataSource)envCtx.lookup("jdbc/SQLServer");

Below are the error messages (notice the ds is fixed, but the rest remains the same):

Connection cannot be resolved to a type
Statement cannot be resolved to a type
SQLException cannot be resolved to a type
e cannot be resolved

Hmm.. what did I miss?
0
 
LVL 10

Assisted Solution

by:mbvvsatish
mbvvsatish earned 600 total points
ID: 17963056
you have imported javax.sql.*;
you also need to import java.sql.*;
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:SWB-Consulting
ID: 17968227
Thanks. It's much better now after adding the object declaration at the front and importing java.sql.*.  However, there is still one error:

"The type ResultSet is ambiguous"

Is it because wrong connection parameters (url) in context.xml or a pure java error?

0
 
LVL 4

Assisted Solution

by:orhanbaba
orhanbaba earned 200 total points
ID: 17975320
use full package name
java.sql.ResultSet result;
0
 

Author Comment

by:SWB-Consulting
ID: 17992416
yes.  now it works!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
How to fix a SonicWall Gateway Anti-Virus firewall blocking automatic updates to apps like Windows, Adobe, Symantec, etc.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question