Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Problem in MS SQL Connection Using JSP

Posted on 2006-11-16
6
Medium Priority
?
1,688 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
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.

 

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

If you are a mobile app developer and especially develop hybrid mobile apps then these 4 mistakes you must avoid for hybrid app development to be the more genuine app developer.
The online market is growing at an unprecedented rate and retail eCommerce sales are expected to reach $4 trillion by 2020. Yet, the profit is not just there for the taking because you have to set yourself apart from the competition.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

670 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