1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
/* Create.java */
import java.sql.*;
public class bdd
{
public static void main(String args[])
{
Connection con = null;
Statement stmt;
String createString;
createString = "create table CLIENTS " +
"(NOM varchar(10), PRENOM varchar(10), AGE int)";
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:postgressql:template1", "postgres", "postgres");
stmt = con.createStatement();
stmt.executeUpdate(createString);
}
// gestion desu cas d'erreur
catch(java.lang.ClassNotFoundException e)
{ System.err.println("Pb de driver : " + e.getMessage()); }
catch(SQLException e)
{ System.err.println("SQLException: " + e.getMessage()); }
// dans tous les cas fermer la connexion
if (con!=null) try {con.close();} catch(Exception e){} }
} |