Erreur code java
Résolu/Fermé
futur ingenieure
Messages postés
133
Date d'inscription
jeudi 26 mars 2009
Statut
Membre
Dernière intervention
2 juin 2012
-
11 mai 2011 à 01:13
beber005 - 11 mai 2011 à 11:08
beber005 - 11 mai 2011 à 11:08
A voir également:
- Erreur code java
- Erreur 0x80070643 - Accueil - Windows
- Waptrick java football - Télécharger - Jeux vidéo
- Jeux java itel football - Télécharger - Jeux vidéo
- Code asci - Guide
- Code puk bloqué - Guide
4 réponses
sakoba2010
Messages postés
157
Date d'inscription
lundi 7 février 2011
Statut
Membre
Dernière intervention
24 juillet 2013
15
11 mai 2011 à 10:54
11 mai 2011 à 10:54
L'erreur c'est à ce niveau:
Essayez ça:
Object[][] data =null;.
Essayez ça:
Object[][] data =new Object[rowCount/*Le nombre de ligne dans votre table*/][columnNames.length].
futur ingenieure
Messages postés
133
Date d'inscription
jeudi 26 mars 2009
Statut
Membre
Dernière intervention
2 juin 2012
1
11 mai 2011 à 09:52
11 mai 2011 à 09:52
Bonjour berber005
oui avec plaisir
merci énormément
import com.mysql.jdbc.*;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.sql.DriverManager;
import java.sql.ResultSet;
public class SimpleTableDemo extends JPanel {
// private boolean DEBUG = false;
public SimpleTableDemo() throws ClassNotFoundException, InstantiationException, IllegalAccessException, SQLException {
super(new GridLayout(1,0));
String[] columnNames = {"Videos","Information"};
String username = "root";
String password = "0000";
Statement stmt;
ResultSet rs;
Class.forName("com.mysql.jdbc.Driver").newInstance();
String url = "jdbc:mysql://localhost:3306/iptv";
Connection conn = (Connection) DriverManager.getConnection(url, username, password);
// System.out.println("OK connexion réussie...");
String Vid ="forgiveMe"/* jTextField1.getText()*/;
stmt = (Statement) conn.createStatement();
rs = stmt.executeQuery("select * from videos where nomVideo='"+Vid+"'");
// String name=rs.getString("nomVideo");
ResultSetMetaData md = (ResultSetMetaData) rs.getMetaData();
int columns = md.getColumnCount();
int k=0;
Object[][] data =null;
System.out.println("testtt");
while (rs.next()) {
// ou ici int k=0;
String inf="";
for (int i=1; i<=columns;i++){
System.out.println("testtttttttttttt");
inf=inf+rs.getArray(i);
}
data[k][1]="image";
data[k][2]=inf;
System.out.println(data.toString());
System.out.println("testttttt");
k++;
}
// rs.close();
// stmt.close();
JTable table = new JTable(data, columnNames);//enlever final
table.setPreferredScrollableViewportSize(new Dimension(500, 70));
table.setFillsViewportHeight(true);
/* if (DEBUG) {
table.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
printDebugData(table);
}
});
}*/
//Create the scroll pane and add the table to it.
JScrollPane scrollPane = new JScrollPane(table);
//Add the scroll pane to this panel.
add(scrollPane);
}
/* private void printDebugData(JTable table) {
int numRows = table.getRowCount();
int numCols = table.getColumnCount();
javax.swing.table.TableModel model = table.getModel();
System.out.println("Value of data: ");
for (int i=0; i < numRows; i++) {
System.out.print(" row " + i + ":");
for (int j=0; j < numCols; j++) {
System.out.print(" " + model.getValueAt(i, j));
}
System.out.println();
}
System.out.println("--------------------------");
}*/
/**
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event-dispatching thread.
*/
private static void createAndShowGUI() {
try {
//Create and set up the window.
JFrame frame = new JFrame("SimpleTableDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Create and set up the content pane.
SimpleTableDemo newContentPane = new SimpleTableDemo();
newContentPane.setOpaque(true); //content panes must be opaque
frame.setContentPane(newContentPane);
//Display the window.
frame.pack();
frame.setVisible(true);
} catch (ClassNotFoundException ex) {
Logger.getLogger(SimpleTableDemo.class.getName()).log(Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
Logger.getLogger(SimpleTableDemo.class.getName()).log(Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
Logger.getLogger(SimpleTableDemo.class.getName()).log(Level.SEVERE, null, ex);
} catch (SQLException ex) {
Logger.getLogger(SimpleTableDemo.class.getName()).log(Level.SEVERE, null, ex);
}
}
public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
oui avec plaisir
merci énormément
import com.mysql.jdbc.*;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.sql.DriverManager;
import java.sql.ResultSet;
public class SimpleTableDemo extends JPanel {
// private boolean DEBUG = false;
public SimpleTableDemo() throws ClassNotFoundException, InstantiationException, IllegalAccessException, SQLException {
super(new GridLayout(1,0));
String[] columnNames = {"Videos","Information"};
String username = "root";
String password = "0000";
Statement stmt;
ResultSet rs;
Class.forName("com.mysql.jdbc.Driver").newInstance();
String url = "jdbc:mysql://localhost:3306/iptv";
Connection conn = (Connection) DriverManager.getConnection(url, username, password);
// System.out.println("OK connexion réussie...");
String Vid ="forgiveMe"/* jTextField1.getText()*/;
stmt = (Statement) conn.createStatement();
rs = stmt.executeQuery("select * from videos where nomVideo='"+Vid+"'");
// String name=rs.getString("nomVideo");
ResultSetMetaData md = (ResultSetMetaData) rs.getMetaData();
int columns = md.getColumnCount();
int k=0;
Object[][] data =null;
System.out.println("testtt");
while (rs.next()) {
// ou ici int k=0;
String inf="";
for (int i=1; i<=columns;i++){
System.out.println("testtttttttttttt");
inf=inf+rs.getArray(i);
}
data[k][1]="image";
data[k][2]=inf;
System.out.println(data.toString());
System.out.println("testttttt");
k++;
}
// rs.close();
// stmt.close();
JTable table = new JTable(data, columnNames);//enlever final
table.setPreferredScrollableViewportSize(new Dimension(500, 70));
table.setFillsViewportHeight(true);
/* if (DEBUG) {
table.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
printDebugData(table);
}
});
}*/
//Create the scroll pane and add the table to it.
JScrollPane scrollPane = new JScrollPane(table);
//Add the scroll pane to this panel.
add(scrollPane);
}
/* private void printDebugData(JTable table) {
int numRows = table.getRowCount();
int numCols = table.getColumnCount();
javax.swing.table.TableModel model = table.getModel();
System.out.println("Value of data: ");
for (int i=0; i < numRows; i++) {
System.out.print(" row " + i + ":");
for (int j=0; j < numCols; j++) {
System.out.print(" " + model.getValueAt(i, j));
}
System.out.println();
}
System.out.println("--------------------------");
}*/
/**
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event-dispatching thread.
*/
private static void createAndShowGUI() {
try {
//Create and set up the window.
JFrame frame = new JFrame("SimpleTableDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Create and set up the content pane.
SimpleTableDemo newContentPane = new SimpleTableDemo();
newContentPane.setOpaque(true); //content panes must be opaque
frame.setContentPane(newContentPane);
//Display the window.
frame.pack();
frame.setVisible(true);
} catch (ClassNotFoundException ex) {
Logger.getLogger(SimpleTableDemo.class.getName()).log(Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
Logger.getLogger(SimpleTableDemo.class.getName()).log(Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
Logger.getLogger(SimpleTableDemo.class.getName()).log(Level.SEVERE, null, ex);
} catch (SQLException ex) {
Logger.getLogger(SimpleTableDemo.class.getName()).log(Level.SEVERE, null, ex);
}
}
public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
futur ingenieure
Messages postés
133
Date d'inscription
jeudi 26 mars 2009
Statut
Membre
Dernière intervention
2 juin 2012
1
11 mai 2011 à 10:54
11 mai 2011 à 10:54
c bon j'ai trouvé l'erreur
c'était au niveau de l'instanciation de tableau data
merci quand même
c'était au niveau de l'instanciation de tableau data
merci quand même