pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Robert Wimmer <seppwimmer@hotmail.com>
To: matteo.traina@email.it
To: pgsql-interfaces@postgresql.org
Subject: Re: jdbc windows
Date: Wed, 28 Jun 2006 17:40:09 +0000
Message-ID: <BAY116-F225E3F283C4CDBAD9909F8D07F0@phx.gbl> (raw)
In-Reply-To: <44A11AC2.3070104@email.it>

>From: Matteo Traina <matteo.traina@email.it>

>i don't understand about use jdbc driver with windows...how do i do for use 
>it, sorry but i need a little guide/trial because i find it only for linux.

the usage of jdbc does not depend on the underlying OS.

here is some example code - that also works in windows

package at.wiro.sql;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Postgres {

  public static void printException(String query,SQLException e)
  {
	System.out.println("query       : <" + query + ">");
	System.out.println("SQL-error   : " + e.getErrorCode());
	System.out.println("SQL-state   : " + e.getSQLState());
	System.out.println("SQL-message : " + e.getMessage());
	e.printStackTrace();
	System.exit(1);
  }

  public static Connection connect(String host,String db, String user, 
String pwd)
  {
	String pg_driver = "org.postgresql.Driver";
	Connection conn = null;
	try { Class.forName(pg_driver); }
    catch (Exception e) {
      System.out.println("can't load postgres driver '" + pg_driver + "' 
...");
      System.exit(1);
      }
    try { conn = DriverManager.getConnection("jdbc:postgresql://" + host + 
"/" + db,user,pwd); }
    catch (SQLException e) {
      System.out.println("can't connect to db '"+db+"' as user '" + user + 
"' ...");
      printException("Connection Error : ",e);
      System.out.println("system halted ...");
      System.exit(1);
      }
	return conn;
  }

  public static ResultSet query(Connection conn,String query)
  {
	ResultSet rs = null;
	try {
	  Statement st = 
conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
	  rs = st.executeQuery(query);
	  }
	catch (SQLException e) { printException(query,e);}
	return rs;
  }

....

regards sepp





view thread (3+ messages)  latest in thread

Message-ID: <BAY116-F225E3F283C4CDBAD9909F8D07F0@phx.gbl>
Permalink:  ../BAY116-F225E3F283C4CDBAD9909F8D07F0@phx.gbl/
Also on:    postgresql.org/message-id/BAY116-F225E3F283C4CDBAD9909F8D07F0@phx.gbl

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-interfaces@postgresql.org
  Cc: seppwimmer@hotmail.com, matteo.traina@email.it
  Subject: Re: jdbc windows
  In-Reply-To: <BAY116-F225E3F283C4CDBAD9909F8D07F0@phx.gbl>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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