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
|
import java.sql.*;
public class makequery_DB{//deb class
public static void main(String args[]) {//main
String url = "jdbc:odbc:JOS";
// String myquery="SELECT DISTINCT CInt(Trim(Right(Left([notice_id],Len([notice_id])-7),Len(Left([notice_id],Len([notice_id])-7))-6))) AS JOS_NUM FROM ojs WHERE (((Month([publication_date]))=12) AND ((Year([publication_date]))=2007)) GROUP BY CInt(Trim(Right(Left([notice_id],Len([notice_id])-7),Len(Left([notice_id],Len([notice_id])-7))-6)));";
String myquery="SELECT DISTINCT jo_planification.jonum, jo_planification.date_pub, jo_planification.year_pub, jo_planification.month_pub, jo_planification.day_pub, jo_planification.bool_report FROM jo_planification WHERE (((jo_planification.date_pub)=#1/4/2008#))GROUP BY jo_planification.jonum, jo_planification.date_pub, jo_planification.year_pub, jo_planification.month_pub, jo_planification.day_pub, jo_planification.bool_report;";
int jonum=0;
int year_pub=0;
int month_pub=0;
int day_pub=0;
Date date_pub;
boolean bool_report=false;
Connection con = null;
try {//try1
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection(url,"","");
Statement requete = con.createStatement();
System.out.println(myquery);
ResultSet resultat= requete.executeQuery(myquery);
while (resultat.next()) { //while
System.out.println("JOS N° : "+resultat.getInt(1));
jonum=resultat.getInt(1);
System.out.println("Date pub : "+resultat.getDate(2));
// date_pub=resultat.getDate(2);
System.out.println("Year pub : "+resultat.getInt(3));
// year_pub=resultat.getInt(3);
System.out.println("Month pub : "+resultat.getInt(4));
// month_pub=resultat.getInt(4);
System.out.println("Day pub : "+resultat.getInt(5));
// day_pub=resultat.getInt(5);
System.out.println("Bool report "+resultat.getBoolean(6));
bool_report=resultat.getBoolean(6);
// System.out.println("Date de publication : "+day_pub+"/"+month_pub+"/"+year_pub);
}; //while
} //try1
catch(Exception e) { System.out.println("Exception -> "+ e); } //try1
finally {//try1
try {con.close();}
catch(SQLException e) {System.out.println("SQLException -> "+e);}
}}} |
Partager