[Tex/LaTex] Package listings: Error “Undefined control sequence.” because of single-quote-symbol

errorshighlightinglistingssymbols

I'm using the package listings and came across a problem displaying an SQL statement within an java environment. This is the MWE.

\documentclass[]{report}
\usepackage{listings}
\definecolor{listinggray}{gray}{0.9}
\definecolor{lbcolor}{rgb}{0.9,0.9,0.9}
\lstset{
 backgroundcolor=\color{lbcolor},
 tabsize=4,
 rulecolor=,
 language=matlab,
 basicstyle=\scriptsize,
 upquote=true,
 aboveskip={1.5\baselineskip},
 columns=fixed,
 showstringspaces=false,
 extendedchars=true,
 breaklines=true,
 prebreak = \raisebox{0ex}[0ex][0ex]{\ensuremath{\hookleftarrow}},
 frame=single,
 showtabs=false,
 showspaces=false,
 showstringspaces=false,
 identifierstyle=\ttfamily,
 keywordstyle=\color[rgb]{0,0,1},
 commentstyle=\color[rgb]{0.133,0.545,0.133},
 stringstyle=\color[rgb]{0.627,0.126,0.941},
}

\begin{document}
\begin{lstlisting}[language=java]
  Connection db = DriverManager.getConnection("jdbc:h2:rel.db", "user", "pass");
  Statement stmt = db.createStatement();
  stmt.execupdate("INSERT INTO CAMPAIGN VALUES ('C1R1R2R3R4R5R6', 1234, 1170, 1189, 1934)");
\end{lstlisting}
\end{document}

The problem is in the 4th line as the SQL statement is using single quotes within a string. I get the latex error (from log):

! Undefined control sequence.
\lst@um'@ ->\lst@ifupquote \textquotesingle 
                                        \else \char 39\relax \fi 
l.299 ...cupdate("INSERT INTO CAMPAIGN VALUES ('C
                                              1R1R2R3R4R5R6', 1234, 117...
The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

How to fix this? Is this a bug – I don't get what's wrong with using single quotes within double quotes?

Update: Solution seems to be adding \usepackage{textcomp} before modifying the listings styles.

Best Answer

Your example works well if you add the two packages to your preamble:

\usepackage{xcolor}
\usepackage{textcomp}

Tested with TeX Live 2012.