From: | "Ribamar FS" <ribafs(at)myrealbox(dot)com> |
---|---|
To: | ElielsonF(at)prodam(dot)sp(dot)gov(dot)br |
Cc: | pgsql-jdbc(at)postgresql(dot)org, pgsql-general(at)postgresql(dot)org, amatsushita(at)prodam(dot)sp(dot)gov(dot)br, claalmeida(at)prodam(dot)sp(dot)gov(dot)br, fsantos(at)prodam(dot)sp(dot)gov(dot)br, mjesus(at)prodam(dot)sp(dot)gov(dot)br, mrmoreira(at)prodam(dot)sp(dot)gov(dot)br, mantonio(at)prodam(dot)sp(dot)gov(dot)br, Marial(at)prodam(dot)sp(dot)gov(dot)br, ptupynamba(at)prodam(dot)sp(dot)gov(dot)br, tnunes(at)prodam(dot)sp(dot)gov(dot)br |
Subject: | Re: RES: [JDBC] Java access pgsql sample |
Date: | 2002-07-26 12:39:52 |
Message-ID: | 1027687192.561feff9ribafs@myrealbox.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general pgsql-jdbc |
Hi (Olá) Elielson!
Thank your for all!
After last tips I move my db to other machine compile and execute fine.
Other libs in my machine?
I don't encounter.
Thank you, thank you very mutch!
-----Original Message-----
From: Elielson Fontanezi <ElielsonF(at)prodam(dot)sp(dot)gov(dot)br>
To: 'Ribamar FS' <ribafs(at)myrealbox(dot)com>
Date: Fri, 26 Jul 2002 09:24:24 -0300
Subject: RES: [JDBC] Java access pgsql sample
Hi!
First of all, you need to put the pgjdbc2.jar in accurate directory.
For example, put the pgjdbc2.jar in $JAVA_HOME/lib and
set CLASSPATH=%CLASSPATH%;%JAVA_HOME%/lib/pgjdbc2.jar.
Segond, be sure that the postgres is accepting conections from
tcpip.
Third, compile the little java program bellow to be sure that you
can
ping the database and then try your program.
Remember, the most common url is: jdbc:postgresql://host:port/dbname
/*
** pgdbping.java - programa para testar uma conexo jdbc com PostGRES
**
** Elielson - 24.07.2002
*/
import java.sql.*;
class pgdbping {
public static void main(String args[]) {
try {
Class.forName("org.postgresql.Driver");
Connection con;
if ( args.length != 3 )
{
String
url =
"jdbc:postgresql://10.10.67.142:5432/formacao_funcionario_des",
user = "postgres",
password = "6lenao";
System.out.println("Uso: java dbping URL user password");
System.out.println("URL jdbc:postgresql://host:port/dbname");
System.out.println("Vou usar conex o interna: " + url
+ ", " + user + ", " + "*******");
con = DriverManager.getConnection(url, user, password);
}
else
{
con = DriverManager.getConnection(args[0], args[1], args[2]);
}
System.out.println("Sucesso na conexo!!");
con.close();
}
catch(Exception e) {
System.out.println("Falha na conex od");
e.printStackTrace();
}
}
}
E.F.:> -----Mensagem original-----
E.F.:> De: Ribamar FS [mailto:ribafs(at)myrealbox(dot)com]
E.F.:> Enviada em: quinta-feira, 25 de julho de 2002 16:11
E.F.:> Para: pgsql-jdbc(at)postgresql(dot)org
E.F.:> Assunto: [JDBC] Java access pgsql sample
E.F.:>
E.F.:>
E.F.:> Hi!
E.F.:>
E.F.:> Help me with this sample. It don't work:
E.F.:>
E.F.:> Linux Conectiva
E.F.:> Postgresql 7.2.1
E.F.:> pgjdbc2.jar
E.F.:>
E.F.:> /etc/profile
E.F.:> JAVA_HOME="/usr/java/jsdk"
E.F.:> J2EE_HOME="/usr/java/j2ee"
E.F.:> CLASSPATH=".:$JAVA_HOME/lib:$J2EE_HOME/lib:/usr/java/jsdk
E.F.:> /corejava/corejava.zip"
E.F.:> J2EE_CLASSPATH=$CLASSPATH
E.F.:> PATH="$PATH:$JAVA_HOME/bin:$J2EE_HOME/bin"
E.F.:> export JAVA_HOME J2EE_HOME CLASSPATH J2EE_CLASSPATH
E.F.:>
E.F.:>
E.F.:> import java.sql.*;
E.F.:> public class SQLStatement {
E.F.:> public static void main(String args[]) {
E.F.:> String url = "jdbc:postgresql:javatest";
E.F.:> Connection con;
E.F.:> String query = "select col1 from test";
E.F.:> Statement stmt;
E.F.:> try {
E.F.:> Class.forName("org.postgresql.Driver");
E.F.:> } catch(java.lang.ClassNotFoundException e) {
E.F.:> System.err.print("ClassNotFoundException: ");
E.F.:> System.err.println(e.getMessage());
E.F.:> }
E.F.:> try {
E.F.:> con =
E.F.:> DriverManager.getConnection(url,"postgres", "postgres");
E.F.:>
E.F.:> stmt = con.createStatement();
E.F.:>
E.F.:>
E.F.:> ResultSet rs = stmt.executeQuery(query);
E.F.:> ResultSetMetaData rsmd = rs.getMetaData();
E.F.:> int numberOfColumns = rsmd.getColumnCount();
E.F.:> int rowCount = 1;
E.F.:> while (rs.next()) {
E.F.:> System.out.println("Linha " +
E.F.:> rowCount + ": ");
E.F.:> for (int i = 1; i <=
E.F.:> numberOfColumns; i++) {
E.F.:> System.out.print("
E.F.:> Coluna " + i + ": ");
E.F.:>
E.F.:> System.out.println(rs.getString(i));
E.F.:> }
E.F.:> System.out.println("");
E.F.:> rowCount++;
E.F.:> }
E.F.:> stmt.close();
E.F.:> con.close();
E.F.:>
E.F.:> } catch(SQLException ex) {
E.F.:> System.err.print("SQLException: ");
E.F.:> System.err.println(ex.getMessage());
E.F.:> }
E.F.:> }
E.F.:> }
E.F.:>
E.F.:>
E.F.:> Errors:
E.F.:> ClassNotFoundException: org/postgresql/Driver
E.F.:> SQLException: driver not found: jdbc:postgresql:javatest
E.F.:>
E.F.:>
E.F.:> Thank you for attention. Sorry ny english (brasilian).
E.F.:>
E.F.:>
E.F.:> ---------------------------(end of
E.F.:> broadcast)---------------------------
E.F.:> TIP 3: if posting/reading through Usenet, please send an
E.F.:> appropriate
E.F.:> subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
E.F.:> message can get through to the mailing list cleanly
E.F.:>
From | Date | Subject | |
---|---|---|---|
Next Message | Scott Gammans | 2002-07-26 13:06:53 | Is there any such thing as PostgreSQL security on a hosted website? |
Previous Message | Elielson Fontanezi | 2002-07-26 12:24:24 | RES: [JDBC] Java access pgsql sample |
From | Date | Subject | |
---|---|---|---|
Next Message | Dave Cramer | 2002-07-26 13:13:39 | Re: PreparedStatement: setting column names dynamically |
Previous Message | Elielson Fontanezi | 2002-07-26 12:24:24 | RES: [JDBC] Java access pgsql sample |