1
I’m creating a website based on the JSP language but I don’t know how to return a consultation which I did in the MSSQL Server, the same goes below:
DECLARE @Nomes VARCHAR(8000)
SELECT @Nomes = COALESCE(@Nomes + ', ', '') + nome
FROM usuarios
WHERE nome IS NOT NULL
PRINT @Nomes
Upshot: name1,Nome2,name3
I have the following code on the JSP page, I want it to return the same value as the query performed on MSSQL Server in a String
<%
Connection currentCon = null;
Statement st = null;
ResultSet rs = null;
try {
currentCon = ConnectionManager.getConnection();
String sql = "DECLARE @Nomes VARCHAR(8000) SELECT @Nomes = COALESCE(@Nomes + ', ', '') + nome FROM usuarios WHERE nome IS NOT NULL";
st = currentCon.createStatement();
rs = st.executeQuery(sql);
String resultado = null;
while(rs.next()) {
resultado = rs.getString(1);
}
System.out.println(test);
} catch (Exception e) {
System.out.println("Falha ao acessar o banco de dados: " + e);
}
%>