Advertisement
Guest User

Untitled

a guest
Jun 14th, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. package swing;
  2.  
  3. import com.sun.org.apache.xpath.internal.SourceTree;
  4.  
  5. import javax.swing.*;
  6. import java.awt.event.ActionEvent;
  7. import java.awt.event.ActionListener;
  8. import java.sql.*;
  9.  
  10. import static swing.database.text_nombre;
  11.  
  12.  
  13. /**
  14. * Created by roberto on 14/06/2016.
  15. */
  16.  
  17. public class buscar implements ActionListener {
  18.  
  19. private static Connection conn;
  20.  
  21. @Override
  22. public void actionPerformed(ActionEvent e) {
  23.  
  24. JOptionPane.showMessageDialog(null,"Libros");
  25.  
  26. String llibres=null;
  27.  
  28. try{
  29.  
  30. conn= DriverManager.getConnection("jdbc:mysql://localhost:3306/biblioteca","root","123321");
  31.  
  32. PreparedStatement sql = conn.prepareStatement("SELECT libros.nombre FROM autores JOIN libros ON autores.id = libros.autor WHERE autores.nombre =?; ");
  33. sql.setString(1,text_nombre.getText());
  34. ResultSet rs=sql.executeQuery();
  35.  
  36. while (rs.next())
  37. {
  38. // llibres+=rs.getString("id");
  39. System.out.println( rs.getString("nombre"));
  40. }
  41.  
  42.  
  43. }catch(SQLException bu){
  44.  
  45. System.out.println("ERROR: " + bu.getMessage());
  46.  
  47. }
  48.  
  49.  
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement