Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package swing;
- import com.sun.org.apache.xpath.internal.SourceTree;
- import javax.swing.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.sql.*;
- import static swing.database.text_nombre;
- /**
- * Created by roberto on 14/06/2016.
- */
- public class buscar implements ActionListener {
- private static Connection conn;
- @Override
- public void actionPerformed(ActionEvent e) {
- JOptionPane.showMessageDialog(null,"Libros");
- String llibres=null;
- try{
- conn= DriverManager.getConnection("jdbc:mysql://localhost:3306/biblioteca","root","123321");
- PreparedStatement sql = conn.prepareStatement("SELECT libros.nombre FROM autores JOIN libros ON autores.id = libros.autor WHERE autores.nombre =?; ");
- sql.setString(1,text_nombre.getText());
- ResultSet rs=sql.executeQuery();
- while (rs.next())
- {
- // llibres+=rs.getString("id");
- System.out.println( rs.getString("nombre"));
- }
- }catch(SQLException bu){
- System.out.println("ERROR: " + bu.getMessage());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement