IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Java Discussion :

Téléchargement HTTP en Java avec MySql/Linux


Sujet :

Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre chevronné
    Inscrit en
    Août 2010
    Messages
    416
    Détails du profil
    Informations forums :
    Inscription : Août 2010
    Messages : 416
    Par défaut Téléchargement HTTP en Java avec MySql/Linux
    Bonjour, j'ai ecrit un petit code en java qui permet le lancement automatique d'un telechargement Http,
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    package marouene;
     
    import java.io.IOException;
    import gcp.httpeasy.Http;
    import gcp.httpeasy.Request;
     
    public class HttpClient {
     
    	/**
             * @param args
             * @throws IOException 
             * 
             */
     
     
     
    	public static double debithttp (String adresse) {
     
    		Request request = Http.get(adresse);
     
    		long start = System.currentTimeMillis();
     
                    //appel au serveur
    		byte[] response = request.asBytes();
     
    		long fin = System.currentTimeMillis();
     
    	return  (double)response.length / (fin - start);
     
    	}
     
    }
    une fois ce code executé ici
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
     
    package marouene;
     
    import java.sql.Connection;
     
    import java.sql.DriverManager;
     
    import java.sql.ResultSet;
     
    import java.sql.SQLException;
     
    import java.sql.Statement;
     
    import java.text.DecimalFormat;
     
     
     
    import java.util.Timer;
     
    import java.io.BufferedWriter;
     
    import java.io.FileWriter;
     
    import java.io.IOException;
     
    import java.io.PrintWriter;
     
    import java.util.TimerTask;
     
    import java.text.*;
     
    import java.util.Locale;
     
     
     
     
     
    public class TestPerformance  {
     
     
     
    	  static int i = 0;
     
    	  static Timer timer;
     
          static double[] tableauftp = new double[10];
     
          static double[] tableauhttp = new double[10];
     
          static Connection con;
     
     
     
    	public static void main(String[] args) {
     
     
     
             class RemindTask extends TimerTask {
     
     
     
    				public void run() {
     
     
     
     
     
    					DecimalFormat df = new DecimalFormat("########.00"); 
     
    					TestFtp ftp = new TestFtp();
     
    					HttpClient http = new HttpClient();
     
    					 try {
     
    						Class.forName("com.mysql.jdbc.Driver");
     
    						 try {
     
    							con =DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/newdata","root","root");
     
    						} catch (SQLException e) {
     
     
     
    							e.printStackTrace();
     
    						}
     
     
     
    					} catch (ClassNotFoundException e) {
     
     
     
    						e.printStackTrace();
     
    					}
     
     
     
    					capture cc = new capture();
     
     
     
    					try {
     
    						Statement stm=con.createStatement();
     
    						int res1=stm.executeUpdate("insert into affichage(heure,ftp) values (now(),"+ftp.calculdebitftp("otn","otnotn","41.228.192.9","/30M"));
     
    						java.sql.Date sDate = new java.sql.Date(System.currentTimeMillis());
     
    		System.out.println(ftp.calculdebitftp("login","mdp","adresse","fichier"));
     
    		//System.out.println(HttpClient.debithttp("adresse"));
     
     
     
     
     
    						//cc.start();
     
     
     
     
     
    					} catch (SQLException e) {
     
    						// TODO Auto-generated catch block
     
    						e.printStackTrace();
     
    					}
     
     
     
     
     
     
     
    			    }
     
    		 }
     
    					 timer = new Timer();
     
    					 timer.scheduleAtFixedRate(new RemindTask(), 0, 300 * 1000);
     
     
     
     
     
     
     
     
     
    	}
     
     
     
     
     
    }
    mais ca me genere ces erreurs la (le code est utilisé en linux)
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
     
    Exception in thread "Timer-0" java.lang.NoClassDefFoundError: org/apache/http/client/methods/HttpRequestBase
    	at java.lang.Class.getDeclaredConstructors0(Native Method)
    	at java.lang.Class.privateGetDeclaredConstructors(Class.java:2406)
    	at java.lang.Class.getConstructor0(Class.java:2716)
    	at java.lang.Class.newInstance0(Class.java:343)
    	at java.lang.Class.newInstance(Class.java:325)
    	at gcp.httpeasy.Http.initHandler(Http.java:41)
    	at gcp.httpeasy.Http.<clinit>(Http.java:35)
    	at marouene.HttpClient.debithttp(HttpClient.java:19)
    	at marouene.TestPerformance$1RemindTask.run(TestPerformance.java:58)
    	at java.util.TimerThread.mainLoop(Timer.java:534)
    	at java.util.TimerThread.run(Timer.java:484)
    Caused by: java.lang.ClassNotFoundException: org.apache.http.client.methods.HttpRequestBase
    	at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
    	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
    	... 11 more
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
     
    com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    	at java.lang.reflect.Constructor.newInstance(Constructor.java:532)
    	at com.mysql.jdbc.Util.handleNewInstance(Util.java:407)
    	at com.mysql.jdbc.Util.getInstance(Util.java:382)
    	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1052)
    	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3603)
    	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3535)
    	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1989)
    	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2150)
    	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2620)
    	at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1664)
    	at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1583)
    	at marouene.TestPerformance$1RemindTask.run(TestPerformance.java:55)
    	at java.util.TimerThread.mainLoop(Timer.java:534)
    	at java.util.TimerThread.run(Timer.java:484)
    com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    	at java.lang.reflect.Constructor.newInstance(Constructor.java:532)
    	at com.mysql.jdbc.Util.handleNewInstance(Util.java:407)
    	at com.mysql.jdbc.Util.getInstance(Util.java:382)
    	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1052)
    	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3603)
    	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3535)
    	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1989)
    	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2150)
    	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2620)
    	at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1664)
    	at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1583)
    	at marouene.TestPerformance$1RemindTask.run(TestPerformance.java:55)
    	at java.util.TimerThread.mainLoop(Timer.java:534)
    	at java.util.TimerThread.run(Timer.java:484)

  2. #2
    Membre éprouvé
    Avatar de _skip
    Homme Profil pro
    Développeur d'applications
    Inscrit en
    Novembre 2005
    Messages
    2 898
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : Suisse

    Informations professionnelles :
    Activité : Développeur d'applications
    Secteur : High Tech - Produits et services télécom et Internet

    Informations forums :
    Inscription : Novembre 2005
    Messages : 2 898
    Par défaut
    Visiblement, la librairie httpclient (je suppose que c'est ça), n'était pas accessible. T'es sûr que t'as bien mis le jar au bon endroit?

  3. #3
    Membre chevronné
    Inscrit en
    Août 2010
    Messages
    416
    Détails du profil
    Informations forums :
    Inscription : Août 2010
    Messages : 416
    Par défaut
    oui j'ai ajouté tous les jar :
    Build path ---> Configure Build path--->Add external jar....
    ke probleme de Http semble resolu

    mais celui de Mysql pas encore ,

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
     
    com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    	at java.lang.reflect.Constructor.newInstance(Constructor.java:532)
    	at com.mysql.jdbc.Util.handleNewInstance(Util.java:407)
    	at com.mysql.jdbc.Util.getInstance(Util.java:382)
    	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1052)
    	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3603)
    	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3535)
    	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1989)
    	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2150)
    	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2620)
    	at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1664)
    	at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1583)
    	at marouene.TestPerformance$1RemindTask.run(TestPerformance.java:54)
    	at java.util.TimerThread.mainLoop(Timer.java:534)
    	at java.util.TimerThread.run(Timer.java:484)

  4. #4
    Membre chevronné
    Inscrit en
    Août 2010
    Messages
    416
    Détails du profil
    Informations forums :
    Inscription : Août 2010
    Messages : 416
    Par défaut
    C'est resolu

    merci _skip

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. java avec mysql
    Par Momo23 dans le forum JDBC
    Réponses: 2
    Dernier message: 23/05/2011, 18h47
  2. Pb de collation avec Mysql (linux)
    Par spearit dans le forum Débuter
    Réponses: 1
    Dernier message: 31/01/2011, 10h29
  3. Réponses: 11
    Dernier message: 15/02/2007, 17h11
  4. Réponses: 2
    Dernier message: 13/02/2007, 16h14
  5. Connexion java avec mysql
    Par hlimaiem dans le forum Installation
    Réponses: 2
    Dernier message: 15/06/2006, 17h37

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo