Olá,
Sou novo no grupo e também em programação java.
Preciso terminar um trabalho, só que estou me matando (literalmente) para usar um campo Date de uma tabela e até agora nada.
A questão é a seguinte:
Estou montando um site em Java e preciso fazer um SELECT e repassar o resultado deste, para uma página web. Qndo os campos da tabela que são passados pelo SELECT são do tipo “Integer, Char, VarChar” funciona blz, mas quando o campo é do tipo “Date” ih, aí dá erro. Uso um Banco Interbase.
Se alguém puder me ajudar agradeço.
Att
Bruno
O código que estou usando é:
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.sql.*;
public class Conpedidodata extends HttpServlet {
private Connection c = null;
private StringBuffer buf = null;
public void init( ServletConfig config )
throws ServletException
{
String url ="jdbc:interbase:///c:/bruno/banco.gdb";
super.init( config );
try {
Class.forName( "interbase.interclient.Driver" );
c = DriverManager.getConnection(url,"SYSDBA","masterkey");
}
catch ( Exception e ) {
e.printStackTrace();
c = null;
}
}
public void doPost ( HttpServletRequest request,
HttpServletResponse response )
throws ServletException, IOException
{
String pedido;
pedido = request.getParameter( "pedido" );
try {
String query = "SELECT P.DTEMISSAO " +
"FROM CLIENTE C, UF U, REPRESENTANTE R, " +
"PEDIDO P, STPEDIDO SP " +
"WHERE C.CDUF = U.CDUF AND " +
"P.CDSTPEDIDO = SP.CDSTPEDIDO AND " +
"P.CDCLIENTE = C.CDCLIENTE AND " +
"C.CDREPRESENTANTE = R.CDREPRESENTANTE AND " +
"P.CDREPRESENTANTE = R.CDREPRESENTANTE AND " +
"P.CDPEDIDO = '" + pedido + "'";
Statement st = c.createStatement();
ResultSet rs = st.executeQuery( query );
ResultSetMetaData rsmd = rs.getMetaData();
buf = new StringBuffer();
buf.append( "<HTML><BODY>
" );
buf.append("<table border= 1 cellspacing=1>");
while ( rs.next() ) {
buf.append("<tr>");
buf.append("<td>" + rs.getDate( 1 ) + "</td>");
buf.append("</tr>");
}
buf.append("</table>");
buf.append( "</BODY></HTML>
" );
st.close();
}
catch ( SQLException sqlex ) {
System.err.println ( "Problemas no Login " );
sqlex.printStackTrace();
}
PrintWriter output;
response.setContentType( "text/html" ); //tipo de conteúdo
output = response.getWriter();
output.println( buf.toString() );
output.close();
}
}
. Pode chamar de Daniel direto
.