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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
| package az;
import java.sql.*;
import java.text.*;
import java.util.*;
import java.sql.Date;
import com.ibm.websphere.*;
public class connexion
{
public static final String driver="com.microsoft.jdbc.sqlserver.SQLServerDriver";
public static final String dbURL="jdbc:microsoft:sqlserver://p2:1433;DatabaseName=allocation";
public static final String loginRoot="rty";
public static final String passwdRoot="aze";
public static final Calendar calendar=Calendar.getInstance();
// La classe DateFormat inclut plusieurs sous-classes de mise en forme de date
public static final DateFormat dateFormat2 =new SimpleDateFormat("dd/MM/yyyy");
public static final DateFormat dateFormat =new SimpleDateFormat("dd/MM/yyyy");
public static Connection conn;
public static Statement stmt;
public static Connection getConnection ()
{
return conn;
}
public static void commit() throws SQLException
{
conn.commit();
}
public static void rollback() throws SQLException
{
conn.rollback();
}
public static void setAutoCommit (boolean autoCommit) throws SQLException
{
conn.setAutoCommit(autoCommit);
}
public static ResultSet executeQuery (String sql) throws SQLException
{
return stmt.executeQuery(sql);
}
public static int executeUpdate(String sql) throws SQLException
{
return stmt.executeUpdate(sql);
}
public static int[] executeBatch () throws SQLException
{
return stmt.executeBatch();
}
public static void addBatch (String sql) throws SQLException
{
stmt.addBatch(sql);
}
//--------------------------------------------------------------------
//La méthode initialize()permet de se connecter à la base de donnée
//--------------------------------------------------------------------
public static void initialize()
{
try
{
System.err.println("initializing...");
Class.forName(driver);
conn=DriverManager.getConnection(dbURL,loginRoot, passwdRoot);
stmt=conn.createStatement();
}
catch (ClassNotFoundException e)
{
System.err.println ("Connexion : driver pas bon");
}
catch (SQLException e)
{
System.err.println ("Connexion : driver non chargé");
}
}
public void finalize()
{
try{
System.err.println("rammassage de la connexion");
conn.close();
System.gc();
}
catch(Exception e){}
}
public static String close()
{
try{
stmt.close();
conn.close();
System.out.println("Fermeture de la conx\n");
}catch(Exception e){System.out.println("erreur1n");}
return "close conx";
}
}
} |
Partager