Advertisement
Guest User

Untitled

a guest
Aug 1st, 2017
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.26 KB | None | 0 0
  1. import java.awt.event.ActionEvent;
  2. import java.awt.event.ActionListener;
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.ResultSet;
  6. import java.sql.SQLException;
  7. import java.sql.Statement;
  8. import java.util.Vector;
  9.  
  10.  
  11.  
  12. public class aggiungi  implements ActionListener {
  13.    
  14.     public Statement cmd = null;
  15.     public Vector colonne,righe = null;
  16.     public ResultSet rs = null;
  17.     @SuppressWarnings("unchecked")
  18.     public void actionPerformed(ActionEvent e) {
  19.  
  20.             try {
  21.                 Class.forName("com.mysql.jdbc.Driver");
  22.                 Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/db", "root", "telecaster" );
  23.                 cmd = con.createStatement();
  24.                 String query = "SELECT * FROM `table`" ;
  25.                 System.out.println(query);
  26.                 rs = cmd.executeQuery(query);  
  27.                 colonne = new Vector();
  28.                 colonne.addElement("nome");
  29.                 colonne.addElement("cognome");
  30.                 colonne.addElement("numero");
  31.                 righe = new Vector();
  32.                 while (rs.next()) {
  33.                 Vector vett = new Vector();
  34.                 vett.addElement(rs.getString("nome"));
  35.                 vett.addElement(rs.getString("cognome"));
  36.                 vett.addElement(rs.getString("numero"));
  37.                 righe.addElement(vett);
  38.                 }
  39.                 } catch (ClassNotFoundException e1) {
  40.                 } catch (SQLException e2) {
  41.                 }
  42.        
  43.         }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement