mardi 26 mai 2009

java : calculer une somme MD5

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;


public class MD5Sample {

/**
* @param args
*/
public static void main(String[] args) {
String algo = "MD5";
System.out.println("calcul du " + algo);
BufferedReader reader =null;
try
{
reader = new BufferedReader(new FileReader("C:/temp/FFT_21117.JPG"));
char [] buffer = new char[4096];
int lus = 0;
StringBuffer stringBuffer = new StringBuffer();

// lecture fichier
while((lus = reader.read(buffer, 0, buffer.length))!=-1)
{
stringBuffer.append(buffer,0,lus);
}

// calcul MD5
byte [] hash = MessageDigest.getInstance(algo).digest(stringBuffer.toString().getBytes());

// convertion de la chaine
StringBuffer hashString = new StringBuffer();
String hex = null;

for(int i = 0; i < hash.length; i++)
{
hex = Integer.toHexString(hash[i]);
if (hex.length() == 1)
{
hashString.append('0');
hashString.append(hex.charAt(hex.length() - 1));
}
else
{
hashString.append(hex.substring(hex.length() - 2));
}
}

System.out.println("calcul du " + algo + " = [" + hashString.toString() + "]");

} catch (FileNotFoundException e) {
e.printStackTrace();
}
catch(IOException e)
{
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
finally
{
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
System.out.println("fin");
}
}

mardi 19 mai 2009

insérer un blob sur oracle avec JDBC

/**
* Creation d'un CLOB temporaire utilisé dans la creation et modification en base.
*
* @param clobData Valeur du CLOB
* @param pC Connection
* @return CLOB
*/
private CLOB getCLOB(String clobData, Connection pC) throws SQLException
{
CLOB tempClob = null;
try {
// create a new temporary CLOB
tempClob = CLOB.createTemporary(pC, true, CLOB.DURATION_SESSION);

// Open the temporary CLOB in readwrite mode to enable writing
tempClob.open(CLOB.MODE_READWRITE);

// Get the output stream to write
Writer tempClobWriter = tempClob.getCharacterOutputStream();

// Write the data into the temporary CLOB
tempClobWriter.write(clobData);

// // Flush and close the stream
tempClobWriter.flush();
tempClobWriter.close();

// Close the temporary CLOB
tempClob.close();
}
catch (Exception exp) {
tempClob.freeTemporary();
throw new SQLException(exp.getMessage());
}
return tempClob;
}

plus d'info sur
: http://www.herongyang.com/jdbc/Oracle-CLOB-getCharacterStream.html

dimanche 17 mai 2009

maven : probleme de conversion de projet strut web

créer le projet strut avec maven
mvn archetype:create -DgroupId=be.realdolmen.struts2 -DartifactId=tutorial -DarchetypeGroupId=org.apache.struts -DarchetypeArtifactId=struts2-archetype-starter -DarchetypeVersion=2.0.11.2


modifier le pom avec ces lignes et relancer avec maven -Dwtp.version=2.0 eclipse:eclipse


< plugin>
< groupId>org.apache.maven.plugins < /groupId >
< artifactId>maven-eclipse-plugin< /artifactId >
< version>2.5-SNAPSHOT < /version >
< configuration >
< downloadSources > false < /downloadSources >
< downloadJavadocs>false < /downloadJavadocs >
< wtpversion>2.0< /wtpversion >
< wtpmanifest>true < /wtpmanifest >
< wtpapplicationxml > true < /wtpapplicationxml >
< /configuration >
< /plugin >

vendredi 15 mai 2009

element oracle

jointure externe sous oracle

SELECT da.DEF_MISSION,
da.DEF_DATE,
da.NIV_PRIO,
da.ETAT,
rst.stat_rst,
rst.stat_prop
FROM TFAFRNDA da
LEFT OUTER JOIN TFAFRNRST rst ON (da.def_mission = rst.no_cnv AND
da.def_date = rst.dh_dep)
WHERE (DEF_MISSION IN ('TOTO))
AND DEF_DATE BETWEEN
TO_DATE('2009/05/15 00:00:00', 'yyyy/mm/dd hh24:mi:ss') AND
TO_DATE('2009/05/15 00:00:00', 'yyyy/mm/dd hh24:mi:ss')
UNION
SELECT rst.no_cnv, rst.dh_dep, null, null, rst.stat_rst, rst.stat_prop
FROM TFAFRNRST rst
WHERE (no_cnv IN ('TOTO))
AND dh_dep BETWEEN
TO_DATE('2009/05/15 00:00:00', 'yyyy/mm/dd hh24:mi:ss') AND
TO_DATE('2009/05/15 00:00:00', 'yyyy/mm/dd hh24:mi:ss')
ORDER BY DEF_MISSION, DEF_DATE ASC

select * from proprietaire p full outer join voiture v on (p.id_utilisateur = v.id_utilisateur)

elements Postgressql

// un exemple de creation de sequence
create sequence seq_id_utilisateur start with 1;

// creation de la table user
CREATE TABLE utilisateur
(
id_utilisateur integer PRIMARY KEY default nextval('seq_id_utilisateur'),
nom VARCHAR(50) NOT NULL,
prenom VARCHAR(50) NOT NULL,
email VARCHAR(50) NOT NULL,
date_activation date
)

insert into proprietaire values (nextval('seq_id_utilisateur'),'spear','britney','britney@yahoo.fr',current_timestamp);

delete from voiture
insert into voiture values ('clio',(select id_utilisateur from proprietaire where nom ='spear'))

elements ksh

#!/bin/ksh
echo 'lancement de la recherche'
OUTPUT_FILE=/users/moi/resultatRecherche.txt
# recherche des occurences à la table
files=`find . -name '*.java' -exec grep -n -i 'TFATRVREC' {} \; -print`
for file in files
do
# ecriture ds un fichier
echo "$file" >> OUTPUT_FILE
grep -i ' *GROUP *' file >> OUTPUT_FILE
done
echo "fin"

mercredi 6 mai 2009

Maven

les commandes utiles sous maven:

Verifier quel est le profil actif:
mvn help:active-profiles

Lorsque vous editez un profil, quels sont les valeurs a utiliser pour une machine (cf. propriété de la JVM):
mvn enforcer:display-info

Debugger les tests unitaires ...
modifier le script de lancement dans le home de maven:
set MAVEN_OPTS=-Xmx512m -XX:MaxPermSize=256m -Xdebug -Xnoagent -Djava.compiler=NONE
-Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n

Configurer le pluggin jetty:
TODO