pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
JDBC Driver Help...
4+ messages / 4 participants
[nested] [flat]

* JDBC Driver Help...
@ 2000-09-04 19:25  Eric Buschelmann <ehb@one.net>
  0 siblings, 2 replies; 4+ messages in thread

From: Eric Buschelmann @ 2000-09-04 19:25 UTC (permalink / raw)
  To: pgsql-interfaces

I am attempting to use the following code.... However, I seem to always
get to the SQL EXCEPTION (on the query)...
What am I doing wrong? I'm sure it is simple -- but still it is
frustrating :) I'm not sure if this is related to the use
of the driver or my configuration -- if anything -- a URL with some
FAQ's would help...
The details in the JDBC (postgres) guide are a little slim...

Thanks
Eric
ehb@One.net



/*
*
* Test.java
*
*/


import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.applet.*;
/* import necessary for PGSQL */
import java.sql.*;



public class Test extends Applet
 implements ActionListener, TextListener {


 Button newButton=new Button("New");

 Panel flow3 = new Panel (new FlowLayout(FlowLayout.LEFT,5,5));
 TextArea textArea2 = new TextArea ("",5,10,TextArea.SCROLLBARS_BOTH);
 Panel border1 = new Panel (new BorderLayout(5,5));


 public void init()
 {
  this.setLayout(new BorderLayout());
  this.setBackground(SystemColor.control);
  this.setForeground(SystemColor.controlText);
  newButton.addActionListener(this);
  flow3.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
  flow3.add(newButton);
  textArea2.setText("Starting text...");
  textArea2.setBackground(SystemColor.window);
  textArea2.setForeground(SystemColor.windowText);
  textArea2.addTextListener(this);
  border1.add("North",flow3);
  border1.add("Center",textArea2);
  add("Center",border1);


 }


 public void actionPerformed(ActionEvent evt)
 {

  if (evt.getSource() == newButton )
   {


     Connection con = null;


     try {
      Class.forName("org.postgresql.Driver").newInstance();
      con=DriverManager.getConnection
("jdbc:postgresql:ehb","ehb","rhimgeti");
      textArea2.setText("SUCCESSFULL connection object");

     }
     catch (SQLException  excpt0)
      {
      textArea2.setText("EXCEPTION0");
      }
     catch (ClassNotFoundException excpt1)
      {
      textArea2.setText("EXCEPTION1");
      }
     catch (InstantiationException excpt2)
      {
      textArea2.setText("EXCEPTION2");
      }
     catch (IllegalAccessException excpt3)
      {
      textArea2.setText("EXCEPTION3");
      }


     /* there should be a connection now*/

     try {
     Statement st = con.createStatement();
     ResultSet rs = st.executeQuery("insert into test values(2);");
     rs.close();


     st.close();
     con.close();
     }

     catch (SQLException excpt0)
         {
      textArea2.setText("SQL EXCEPTION ON QUERY!!!");
         }




   }


 }



 public void textValueChanged(TextEvent evt) {
  String[] test = new String[2];
 }

} /* end class*/








^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: JDBC Driver Help...
@ 2000-09-06 05:47  Joachim Achtzehnter <joachim@kraut.bc.ca>
  parent: Eric Buschelmann <ehb@one.net>
  1 sibling, 0 replies; 4+ messages in thread

From: Joachim Achtzehnter @ 2000-09-06 05:47 UTC (permalink / raw)
  To: pgsql-interfaces

Yesterday, in a message to pgsql-interfaces, Eric Buschelmann wrote:
> 
> public class Test extends Applet

You should try an application first before complicating things with applet
issues. Once you get JDBC working with an application you can go on to an
applet.

>       Class.forName("org.postgresql.Driver").newInstance();

Creating an instance is not necessary, just load the class:

  Class.forName("org.postgresql.Driver");

>       con=DriverManager.getConnection("jdbc:postgresql:ehb","ehb","rhimgeti");

This looks ok.

>      catch (SQLException excpt0)
>          {
>       textArea2.setText("SQL EXCEPTION ON QUERY!!!");
>          }

To obtain some more info about the failure print a stack trace:

  excpt0.printStackTrace();

Are you running the postmaster with the -i flag? Did you configure
Postgresql to permit TCP connections from the host where your
application/applet runs?

Joachim

-- 
work:     joachima@realtimeint.com (http://www.realtimeint.com)
private:  joachim@kraut.bc.ca      (http://www.kraut.bc.ca)





^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* RE: JDBC Driver Help...
@ 2000-09-06 08:34  Peter Mount <petermount@maidstone.gov.uk>
  0 siblings, 0 replies; 4+ messages in thread

From: Peter Mount @ 2000-09-06 08:34 UTC (permalink / raw)
  To: 'Eric Buschelmann' <ehb@one.net>; pgsql-interfaces

INSERT doesn't return any results, so your use of executeQuery() is wrong
here, and an SQLException should be thrown.

You should use executeUpdate() for any SQL statements that don't return a
ResultSet.

PS: If you were writing a shell, so don't know if a ResultSet would be
returned or not, then theres the execute() method, but you have to handle
the results differently, so you should stay away from it.

Peter

-- 
Peter Mount
Enterprise Support Officer, Maidstone Borough Council
Email: petermount@maidstone.gov.uk
WWW: http://www.maidstone.gov.uk
All views expressed within this email are not the views of Maidstone Borough
Council


-----Original Message-----
From: Eric Buschelmann [mailto:ehb@one.net]
Sent: Monday, September 04, 2000 8:25 PM
To: pgsql-interfaces@postgresql.org
Subject: [INTERFACES] JDBC Driver Help...


I am attempting to use the following code.... However, I seem to always
get to the SQL EXCEPTION (on the query)...
What am I doing wrong? I'm sure it is simple -- but still it is
frustrating :) I'm not sure if this is related to the use
of the driver or my configuration -- if anything -- a URL with some
FAQ's would help...
The details in the JDBC (postgres) guide are a little slim...

Thanks
Eric
ehb@One.net



/*
*
* Test.java
*
*/


import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.applet.*;
/* import necessary for PGSQL */
import java.sql.*;



public class Test extends Applet
 implements ActionListener, TextListener {


 Button newButton=new Button("New");

 Panel flow3 = new Panel (new FlowLayout(FlowLayout.LEFT,5,5));
 TextArea textArea2 = new TextArea ("",5,10,TextArea.SCROLLBARS_BOTH);
 Panel border1 = new Panel (new BorderLayout(5,5));


 public void init()
 {
  this.setLayout(new BorderLayout());
  this.setBackground(SystemColor.control);
  this.setForeground(SystemColor.controlText);
  newButton.addActionListener(this);
  flow3.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
  flow3.add(newButton);
  textArea2.setText("Starting text...");
  textArea2.setBackground(SystemColor.window);
  textArea2.setForeground(SystemColor.windowText);
  textArea2.addTextListener(this);
  border1.add("North",flow3);
  border1.add("Center",textArea2);
  add("Center",border1);


 }


 public void actionPerformed(ActionEvent evt)
 {

  if (evt.getSource() == newButton )
   {


     Connection con = null;


     try {
      Class.forName("org.postgresql.Driver").newInstance();
      con=DriverManager.getConnection
("jdbc:postgresql:ehb","ehb","rhimgeti");
      textArea2.setText("SUCCESSFULL connection object");

     }
     catch (SQLException  excpt0)
      {
      textArea2.setText("EXCEPTION0");
      }
     catch (ClassNotFoundException excpt1)
      {
      textArea2.setText("EXCEPTION1");
      }
     catch (InstantiationException excpt2)
      {
      textArea2.setText("EXCEPTION2");
      }
     catch (IllegalAccessException excpt3)
      {
      textArea2.setText("EXCEPTION3");
      }


     /* there should be a connection now*/

     try {
     Statement st = con.createStatement();
     ResultSet rs = st.executeQuery("insert into test values(2);");
     rs.close();


     st.close();
     con.close();
     }

     catch (SQLException excpt0)
         {
      textArea2.setText("SQL EXCEPTION ON QUERY!!!");
         }




   }


 }



 public void textValueChanged(TextEvent evt) {
  String[] test = new String[2];
 }

} /* end class*/







^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: JDBC Driver Help...
@ 2000-09-06 12:56  Bob Kline <bkline@rksystems.com>
  parent: Eric Buschelmann <ehb@one.net>
  1 sibling, 0 replies; 4+ messages in thread

From: Bob Kline @ 2000-09-06 12:56 UTC (permalink / raw)
  To: Eric Buschelmann <ehb@one.net>; +Cc: pgsql-interfaces

On Mon, 4 Sep 2000, Eric Buschelmann wrote:

> I am attempting to use the following code.... However, I seem to always
> get to the SQL EXCEPTION (on the query)... [snip]
>      ResultSet rs = st.executeQuery("insert into test values(2);");
>      rs.close();
> 
> 
>      st.close();
>      con.close();
>      }
> 
>      catch (SQLException excpt0)
>          {
>       textArea2.setText("SQL EXCEPTION ON QUERY!!!");
>          }

The two most egregious problems are the fact that you're not letting the
exception objects tell you what they know, and the semicolon isn't part
of the SQL syntax -- lose it.

-- 
Bob Kline
mailto:bkline@rksystems.com
http://www.rksystems.com




^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2000-09-06 12:56 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2000-09-04 19:25 JDBC Driver Help... Eric Buschelmann <ehb@one.net>
2000-09-06 05:47 ` Joachim Achtzehnter <joachim@kraut.bc.ca>
2000-09-06 12:56 ` Bob Kline <bkline@rksystems.com>
2000-09-06 08:34 RE: JDBC Driver Help... Peter Mount <petermount@maidstone.gov.uk>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox