Hello Marcel,
Monday, August 07, 2000, 1:59:18 AM, you wrote:
MvK> When I use queries in a JavaBean, using JDBC classes and interfaces, to
MvK> get data from the database, there is no problem. However, now I want to
MvK> use a variable in a subquery of a query, e.g. in the query I mentioned
MvK> below I want to replace "Voorstellingcode = 1" by "Voorstellingcode =
MvK> var".
MvK> What is the syntax of that??
MvK> ("SELECT Count(Stoel.Rijnummer) AS cinr FROM Stoel GROUP BY
MvK> Stoel.Rijnummer, Stoel.Zaalcode HAVING Stoel.Zaalcode IN (SELECT
MvK> Zaalcode FROM Voorstelling WHERE Voorstellingcode = 1)");
You can not directly place variable name to SQL query. Dynamically
build SQL query string or use Prepare/Bind actions.
For example:
1. build SQL string:
String sql = "SELECT Count(Stoel.Rijnummer) AS cinr FROM Stoel GROUP BY
Stoel.Rijnummer, Stoel.Zaalcode HAVING Stoel.Zaalcode IN (SELECT
Zaalcode FROM Voorstelling WHERE Voorstellingcode = " + var + ")";
where var store needed value
2. prepare/bind
int val = 1;
String sql = "SELECT Count(Stoel.Rijnummer) AS cinr FROM Stoel GROUP BY
Stoel.Rijnummer, Stoel.Zaalcode HAVING Stoel.Zaalcode IN (SELECT
Zaalcode FROM Voorstelling WHERE Voorstellingcode = ?)";
PreparedStatement stmt = connection.prepareStatement(sql);
stmt.setInt( 1, val);
ResultSet rs = stms.executeQuery();
and relax...
--
Best regards,
Oleg mailto:[EMAIL PROTECTED]
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets