Erreur code java String[][]
Résolu
futur ingenieure
Messages postés
133
Date d'inscription
Statut
Membre
Dernière intervention
-
futur ingenieure Messages postés 133 Date d'inscription Statut Membre Dernière intervention -
futur ingenieure Messages postés 133 Date d'inscription Statut Membre Dernière intervention -
Salut,
j'ai crée la classe suivante :
public class operation {
public String[][] operationn(@WebParam(name = "key")
String key) {
String [][]data =null;
try {
//TODO write your implementation code here:
String[] columnNames = {"Videos", "Information"};
//---------Cconnexion à la base de données:----------------------
String username = "root";
String password = "0000";
Statement stmt;
ResultSet rs;
Class.forName("com.mysql.jdbc.Driver").newInstance();
String url = "jdbc:mysql://localhost:3306/mabase";
Connection conn = null;
conn = (Connection) DriverManager.getConnection(url, username, password);
System.out.println("OK connexion réussie...");
stmt = (Statement) conn.createStatement();
rs = stmt.executeQuery("select * from videos where nomVideo='" + key + "'");
rs.last();
int NbreResultats = rs.getRow();// n' a pas de sens non?
System.out.println("Le nombre des résultats vaut " + NbreResultats); // to del
data = new String[NbreResultats][columnNames.length];
rs.beforeFirst();
String NEWLINE = System.getProperty("line.separator");
while (rs.next()) {
String im = rs.getString("lien");
System.out.println(im); // to del
String Info = ""+" Nom de la vidèo :" + rs.getString("nomVideo") + NEWLINE + " Catégorie :" + rs.getString("categorie") + NEWLINE + " Durée :" + rs.getString("duree") + NEWLINE;
System.out.println(Info);
int i=0;
data[i][0] =rs.getString("vignette");
data[i][1] = Info;
i++;
}
rs.close();
stmt.close();
} catch (SQLException ex) {
//System.out.println("erreur sqlex");//
Logger.getLogger(operation.class.getName()).log(Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
// System.out.println("erreur Inst"); //
Logger.getLogger(operation.class.getName()).log(Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
// System.out.println("erreur ill");//
Logger.getLogger(operation.class.getName()).log(Level.SEVERE, null, ex);
} catch (ClassNotFoundException ex) {
// System.out.println("erreur class not found");
Logger.getLogger(operation.class.getName()).log(Level.SEVERE, null, ex);
}
return data;
}
public static void main (String [] args){
operation op = new operation();
System.out.println(op.operationn("exemple"));
}
}
pas d'erreur mais comme output il m'affiche [[Ljava.lang.String;@b32e13d !!!!!!
c'est quoi le probléme SVP?
merci d'avance
j'ai crée la classe suivante :
public class operation {
public String[][] operationn(@WebParam(name = "key")
String key) {
String [][]data =null;
try {
//TODO write your implementation code here:
String[] columnNames = {"Videos", "Information"};
//---------Cconnexion à la base de données:----------------------
String username = "root";
String password = "0000";
Statement stmt;
ResultSet rs;
Class.forName("com.mysql.jdbc.Driver").newInstance();
String url = "jdbc:mysql://localhost:3306/mabase";
Connection conn = null;
conn = (Connection) DriverManager.getConnection(url, username, password);
System.out.println("OK connexion réussie...");
stmt = (Statement) conn.createStatement();
rs = stmt.executeQuery("select * from videos where nomVideo='" + key + "'");
rs.last();
int NbreResultats = rs.getRow();// n' a pas de sens non?
System.out.println("Le nombre des résultats vaut " + NbreResultats); // to del
data = new String[NbreResultats][columnNames.length];
rs.beforeFirst();
String NEWLINE = System.getProperty("line.separator");
while (rs.next()) {
String im = rs.getString("lien");
System.out.println(im); // to del
String Info = ""+" Nom de la vidèo :" + rs.getString("nomVideo") + NEWLINE + " Catégorie :" + rs.getString("categorie") + NEWLINE + " Durée :" + rs.getString("duree") + NEWLINE;
System.out.println(Info);
int i=0;
data[i][0] =rs.getString("vignette");
data[i][1] = Info;
i++;
}
rs.close();
stmt.close();
} catch (SQLException ex) {
//System.out.println("erreur sqlex");//
Logger.getLogger(operation.class.getName()).log(Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
// System.out.println("erreur Inst"); //
Logger.getLogger(operation.class.getName()).log(Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
// System.out.println("erreur ill");//
Logger.getLogger(operation.class.getName()).log(Level.SEVERE, null, ex);
} catch (ClassNotFoundException ex) {
// System.out.println("erreur class not found");
Logger.getLogger(operation.class.getName()).log(Level.SEVERE, null, ex);
}
return data;
}
public static void main (String [] args){
operation op = new operation();
System.out.println(op.operationn("exemple"));
}
}
pas d'erreur mais comme output il m'affiche [[Ljava.lang.String;@b32e13d !!!!!!
c'est quoi le probléme SVP?
merci d'avance
A voir également:
- Erreur code java String[][]
- Code ascii - Guide
- Waptrick java football - Télécharger - Jeux vidéo
- Jeux java itel - Télécharger - Jeux vidéo
- Code puk bloqué - Guide
- Eclipse java - Télécharger - Langages
3 réponses
Hello ;-)
Cette fois je vois de suite le souci ^.^
Tu fais un system.println directement sur l'objet retourné par ta fonction, hors l'objet en question est un tableau, et donc effectivement il t'affiche "l'adresse" de l'objet tableau mais pas ses valeurs.
pour les afficher, il va falloir faire une boucle ;-)
Cette fois je vois de suite le souci ^.^
Tu fais un system.println directement sur l'objet retourné par ta fonction, hors l'objet en question est un tableau, et donc effectivement il t'affiche "l'adresse" de l'objet tableau mais pas ses valeurs.
pour les afficher, il va falloir faire une boucle ;-)