Advertisement
Guest User

Untitled

a guest
Aug 30th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. public void insertarLibro()
  2. {
  3. String url = "jdbc:sqlserver://localhost:1433;databaseName=Biblioteca";
  4. String user = "mi_usuario";
  5. String password = "mi_contraseña";
  6. String fk_dni = "SELECT dni FROM Autores WHERE nombre = '?'";
  7.  
  8.  
  9. try
  10. {
  11. Connection cn = DriverManager.getConnection(url, user, password);
  12. PreparedStatement ps = cn.prepareStatement(fk_dni);
  13. ResultSet rs = ps.executeQuery();
  14. String nombre = (String)cboAutor.getSelectedItem();
  15.  
  16. while(rs.next())
  17. {
  18. ps.setString(1, nombre);
  19. }
  20.  
  21. System.out.println("DNI : " + rs.getString(1));
  22. }
  23. catch(SQLException e)
  24. {
  25. System.out.println("ERROR : ");
  26. e.printStackTrace(System.out);
  27. }
  28.  
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement