I use the following lstlisting (listings package):
\documentclass{thesis}
\usepackage{ucs}
\usepackage[utf8]{inputenc}
\usepackage{url}
\usepackage{bbding}
\usepackage{listings}
\usepackage{tikz}
\usepackage[center]{caption}
\usepackage{tabularx}
\usepackage{amssymb}
\usepackage{array}
\usepackage{nameref}
\usepackage[section]{placeins}
\usepackage{graphicx}
\usepackage{calc} \newlength\tdima \newlength\tdimb \setlength\tdima{ \fboxsep+\fboxrule} \setlength\tdimb{-\fboxsep+\fboxrule}
\DeclareCaptionFont{white}{\color{white}}
\DeclareCaptionFormat{listing}{\colorbox{gray}{\parbox{\textwidth}{#1#2#3}}}
\captionsetup[lstlisting]{format=listing,labelfont=white,textfont=white}
\begin{document}
\lstset{language=SQL,morekeywords={PREFIX,java,rdf,rdfs,url}}
\begin{lstlisting}[captionpos=t,label=lst:sparql,caption=SPARQL query to retrieve the names of each package in a software project,frame=tlrb, xleftmargin = \tdima, xrightmargin = \tdimb, rulecolor= \color{gray}]
PREFIX java: <http://evolizer.org/ontologies/seon/2009/06/java.owl#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?url ?name
WHERE {
?url rdf:type java:Package .
?url rdfs:label ?name
}
\end{lstlisting}
\end{document}
As one can see I set the rulecolor to gray. But I want to set the rule color only for the top line of the frame to gray. All the other lines (left, right, bottom) should stay black. How can I achieve that?

\tdimaandtdimbare undefined. Presumably you want to copy Herbert's answer to this question – Seamus Apr 5 '11 at 11:25