Thread: a JDBC applet

a JDBC applet

From
Cyril FERRAND
Date:
Hello

    I look for an example of a Java applet to communicate with a
postgresql base via JBDC. Because I have a lot of pb with my own one.
A example like basic.java example is ok.

thanks...

Cyril

--
*************************************************************************
*       Cyril Ferrand : mailto:cyril.ferrand@sophia.inria.fr            *
*            http://www.mygale.org/05/ironmask                          *
*************************************************************************




Re: [INTERFACES] a JDBC applet

From
"Andrew R. Jackson"
Date:
At 04:49 PM 09/07/98 +0200, Cyril FERRAND wrote:
>    I look for an example of a Java applet to communicate with a
>postgresql base via JBDC. Because I have a lot of pb with my own one.
>A example like basic.java example is ok.

I have a general question related to this connecting to the DB via applet: would this require the applet user's domain
tobe in the pg_hba.conf file? I couldn't successfully run basic.java (one of the examples) locally here and have it
connectto Postgres at school without doing this first. 

If one wants an applet that can run anywhere to have access, then you'd have to set up Postgres not to only accept
connectionsfrom certain domains, but all domains, right? I could be way off here since I am a lowly Postgres *user*,
andmost docs/discussion speak to people who have Postgres admin/config abilities, which is unfortunate. 

Anyway, my approach to the applet-Postgres issue is a client-server one. Applets are clients that connect to a server
runningon the same machine running the Postgres stuff which mediates the database connection. This will keep the
sysadminpeople happy :) At least at my school... 

Andrew


Re: [INTERFACES] a JDBC applet

From
Peter T Mount
Date:
On Thu, 9 Jul 1998, Andrew R. Jackson wrote:

> At 04:49 PM 09/07/98 +0200, Cyril FERRAND wrote:
> >    I look for an example of a Java applet to communicate with a
> >postgresql base via JBDC. Because I have a lot of pb with my own one.
> >A example like basic.java example is ok.
>
> I have a general question related to this connecting to the DB via
> applet: would this require the applet user's domain to be in the
> pg_hba.conf file? I couldn't successfully run basic.java (one of the
> examples) locally here and have it connect to Postgres at school without
> doing this first.

Yes, anything that connects to the server needs to be in pg_hba.conf

> If one wants an applet that can run anywhere to have access, then you'd
> have to set up Postgres not to only accept connections from certain
> domains, but all domains, right? I could be way off here since I am a
> lowly Postgres *user*, and most docs/discussion speak to people who have
> Postgres admin/config abilities, which is unfortunate.

You are correct, although you would do this at a database by database
level, rather than all databases.

> Anyway, my approach to the applet-Postgres issue is a client-server one.
> Applets are clients that connect to a server running on the same machine
> running the Postgres stuff which mediates the database connection. This
> will keep the sysadmin people happy :) At least at my school...

Personally, I work with Java applications rather than applets, because my
code isn't really suited to a browser environment. Most of the time it's
on the same machine as postgres, but a lot of the time, it's another
machine on my local network, so it's not much of a problem.

But for those who do write applets for External web use, they have to
account for it.

I think the following should work:

host    mydb    0.0.0.0    0.0.0.0    password

I'd ill advise using trust, as they could get in as the DBA, and ident
wouldn't work well with most browsers (actually I can't think of any that
would work).

--
Peter T Mount peter@retep.org.uk or petermount@earthling.net
Main Homepage: http://www.retep.org.uk
************ Someday I may rebuild this signature completely ;-) ************
Work Homepage: http://www.maidstone.gov.uk Work EMail: peter@maidstone.gov.uk


Re: [INTERFACES] a JDBC applet

From
Anil Amarakoon
Date:
Hi!

Postgres 6.3.2 - Redhat 4.2, 5.0,  5.1, (JDK-from blackdown.org) Windoz  NT
4.0 & 95 (Sun JDK) Mac (Metrowerk-JDK lite)
=====================================================================
Connection conn;
Statement stmt;
Resultset rest;

To get Connection:

public void openDir() {

try {
 Class.forName("postgresql.Driver");
conn=DriverManager.getConnection("jdbc:postgresql://liman.awcl.com:5432/adsys","user
Name","passwd");
}catch(SQLException sqle) {
 System.out.println("connection failed");
 sqle.printStackTrace();
}catch(ClassNotFoundException cnfe) {      //optional
 System.out.println("Class not found");
 cnfe.printStackTrace();
}catch(Exception e) {      //optional
 e.printStackTrace(); }

 }



then query:

public void getCusNum()
{
String query1 = "select cnumber from tcustomer";
      vcusNum = new Vector();
try{
stmt = conn.createStatement();
rest = stmt.executeQuery(query1);

while (rest.next()) {
  vcusNum.addElement(new Integer(rest.getInt(1)));
 }
}catch(SQLException sqle) {
}catch(Exception e) {}

}




close the connection:


public void closeDirectory() {

try{
 if(rest != null){
  rest.close();
  rest = null; }
 if(stmt != null) {
  stmt.close();
  stmt = null; }
 if(conn != null) {
  conn.close();
  conn = null; }
 } catch(SQLException sqle) {
  sqle.printStackTrace(); }
 }


Cyril FERRAND wrote:

> Hello
>
>     I look for an example of a Java applet to communicate with a
> postgresql base via JBDC. Because I have a lot of pb with my own one.
> A example like basic.java example is ok.
>
> thanks...
>
> Cyril