Connexion java postgresql
workflow
Messages postés
1
Date d'inscription
Statut
Membre
Dernière intervention
-
labiko445 -
labiko445 -
bonjour tout le monde ;
voila j'ai un problème au niveau de la connexion entre mon Postgresql (BD) et java je n'arrive pas à établir la connexion entre deux postes ou un est un serveur (ou est installée ma BD) et l'autre c un client qui peut faire toutes les reqêtes SQL sur ma BD?voila ma portion de code je ne sais pas si c un problème dans mon code ou de configuration de mon PostgreSQL?????
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.*;
public class Connect {
public Connection getConnection()
throws SQLException, ClassNotFoundException {
String dbUrl = "jdbc:postgresql://localhost/workflow";
String user ="postgres";
String password = "workflow";
Class.forName("org.postgresql.Driver"); //Driver
Connection c = DriverManager.getConnection(dbUrl, user, password);
//Statement s = c.createStatement();
System.out.println( " la connection est etabli, bravo !!!!");
return c;
}
public static void main(String[] args)throws Exception, SQLException,
ClassNotFoundException {
Connect m = new Connect();
Connection c = m.getConnection();
Statement instruction = c.createStatement();
}
}
merci beaucoup c très urgent
voila j'ai un problème au niveau de la connexion entre mon Postgresql (BD) et java je n'arrive pas à établir la connexion entre deux postes ou un est un serveur (ou est installée ma BD) et l'autre c un client qui peut faire toutes les reqêtes SQL sur ma BD?voila ma portion de code je ne sais pas si c un problème dans mon code ou de configuration de mon PostgreSQL?????
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.*;
public class Connect {
public Connection getConnection()
throws SQLException, ClassNotFoundException {
String dbUrl = "jdbc:postgresql://localhost/workflow";
String user ="postgres";
String password = "workflow";
Class.forName("org.postgresql.Driver"); //Driver
Connection c = DriverManager.getConnection(dbUrl, user, password);
//Statement s = c.createStatement();
System.out.println( " la connection est etabli, bravo !!!!");
return c;
}
public static void main(String[] args)throws Exception, SQLException,
ClassNotFoundException {
Connect m = new Connect();
Connection c = m.getConnection();
Statement instruction = c.createStatement();
}
}
merci beaucoup c très urgent
A voir également:
- Connexion java postgresql
- Gmail connexion - Guide
- Waptrick java football - Télécharger - Jeux vidéo
- Jeux java itel - Télécharger - Jeux vidéo
- Eclipse java - Télécharger - Langages
- Java apk - Télécharger - Langages
3 réponses
vous pouvez essaiyez ce Code:
/**
* @(#)Mahmoud.java
*
*
* @author
* @version 1.00 2009/11/11
*/
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.SQLException;
public class JDBCExample {
public static void main(String[] arg) {
System.out.println("-------- PostgreSQL JDBC Connection Testing ------------");
try {
Class.forName("org.postgresql.Driver");
} catch (ClassNotFoundException e) {
System.out.println("Where is your PostgreSQL JDBC Driver? Include in your library path!");
e.printStackTrace();
return;
}
System.out.println("PostgreSQL JDBC Driver Registered!");
Connection connection = null;
try {
connection = DriverManager.getConnection("jdbc:postgresql://127.0.0.1:5432/test","mah", "123456");
} catch (SQLException e) {
System.out.println("Connection Failed! Check output console");
e.printStackTrace();
return;
}
if (connection != null)
System.out.println("You made it, take control your database now!");
else
System.out.println("Failed to make connection!");
}
}
/**
* @(#)Mahmoud.java
*
*
* @author
* @version 1.00 2009/11/11
*/
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.SQLException;
public class JDBCExample {
public static void main(String[] arg) {
System.out.println("-------- PostgreSQL JDBC Connection Testing ------------");
try {
Class.forName("org.postgresql.Driver");
} catch (ClassNotFoundException e) {
System.out.println("Where is your PostgreSQL JDBC Driver? Include in your library path!");
e.printStackTrace();
return;
}
System.out.println("PostgreSQL JDBC Driver Registered!");
Connection connection = null;
try {
connection = DriverManager.getConnection("jdbc:postgresql://127.0.0.1:5432/test","mah", "123456");
} catch (SQLException e) {
System.out.println("Connection Failed! Check output console");
e.printStackTrace();
return;
}
if (connection != null)
System.out.println("You made it, take control your database now!");
else
System.out.println("Failed to make connection!");
}
}