Hi al .....
I try to connect database by servlet and storing the
result to applet.
Servlet is working good, servlet-applet communication
also ok.
The problem is the result not appear ( by appletviewer
or from netscape).
Help me please.
This is the servlet code :..........res.setContentType("text/plain");PrintWriter out = res.getWriter();
try { Class.forName("org.postgresql.Driver"); con = DriverManager.getConnection(
"jdbc:postgresql:lecture","me", "pass"); stmt = con.createStatement(); rs = stmt.executeQuery("SELECT K_ID,
K_NAME,
TERM, DATE FROM KAMOKU"); while(rs.next()) { out.println(rs.getString(1) + " " +
rs.getString(2) + " " + rs.getString(3) + " " +
rs.getDate(4).toString()); } } catch(ClassNotFoundException e) ..........
The applet code :
import java.applet.*;
import java.awt.*;
import java.io.*;
import java.net.URL;
import com.oreilly.servlet.HttpMessage;
public class applettoservlet2 extends Applet
{ TextArea httpText; public void init() { httpText = new TextArea(); }
public void start() { refresh(); }
private void refresh() { httpText.setText(HttpText()); }
private String HttpText() { try { URL url = new
URL("http://localhost:8088/servlet/servlettoapplet"); HttpMessage msg = new HttpMessage(url);
InputStreamin = msg.sendGetMessage(); DataInputStream result = new
DataInputStream(new
BufferedInputStream(in)); String date = result.readLine(); in.close(); return date; }
catch(Exception e) { e.printStackTrace(); return null; } }
}
Thank you,
S.A.Pamungkas
__________________________________________________
Do You Yahoo!?
Get Yahoo! Mail - Free email you can access from anywhere!
http://mail.yahoo.com/