Electric Field Created by a Uniformly Charged Rod of Finite Length
We consider a rod of length $L$ carrying a charge $Q$ distributed uniformly along its length.
Because the rod is uniformly charged, we define the linear charge density $\lambda $ which represents the charge per unit length of the rod and is equal to
\lambda =\frac{Q}{L}
Electric field on one side of the rod (point }$\mathbf{P}$:
The charge $Q$ is continuously distributed along the rod and we therefore consider the contribution of an infinitesimal portion $dx$ with infinitesimal charge $dq=\lambda dx$.
The electric field $d{\overrightarrow{E}}_x$ created by this portion of the rod at $x=a$ is directed along $\overrightarrow{x}$ and has magnitude $dE_x$ given by
dE_x=\frac{kdq}{{\left(a-x\right)}^2}=\frac{k\lambda dx}{{\left(x-a\right)}^2}=\frac{kQ}{{\left(x-a\right)}^2L}dx
Any such portion of the rod creates an electric field $d{\overrightarrow{E}}_x$ that lies along the $x$-axis and therefore, to derive the electric field created by the entire rod, we integrate from $x=0$ to $x=L$ as follows
\begin{aligned} E_x&=\int^L_0{\frac{kQ}{{\left(x-a\right)}^2L}dx} = \frac{kQ}{L}{\left[-\frac{1}{x-a}\right]}^L_0 = \frac{kQ}{L}\left[-\frac{1}{L-a}+\left(-\frac{1}{a}\right)\right] = \frac{kQ}{a\left(a-L\right)} \end{aligned}
Thus, the electric field at $x=a$ is equal to
\boxed{{\overrightarrow{E}}_x=\frac{kQ}{a\left(a-L\right)}\hat{x}}
Electric field above the center of the rod (point }$\mathbf{P}$:
The charge $Q$ is continuously distributed along the rod and we therefore consider the contribution of an infinitesimal portion $dx$ with infinitesimal charge $dQ=\lambda dx$.
By symmetry, we conclude that the net electric field at point $P$ is directed along the $y$-axis and has no horizontal component. Indeed, for any (red) infinitesimal charge $dQ$ located on the left side of the rod, an equivalent (green) infinitesimal charge $dQ$ can be found on the right side of the rod. When considering the infinitesimal electric fields they create at point $P$, we conclude that their horizontal components cancels and that, therefore, the net electric field at point $P$ has no horizontal component and is vertical (upward). We therefore only seek to compute the $y$-component of the electric field at point $P$.
To derive the net electric field at point $P$, we consider one of the charges $dQ$ and argue that it creates an infinitesimal field $d\overrightarrow{E}$ with a $y$-component $dE_y$ given by:
dE_y=dE{\mathrm{cos} \left(\theta \right)\ }=\frac{kdQ}{x^2+h^2}\cdot {\mathrm{cos} \left(\theta \right)\ }
Recalling that ${\mathrm{cos} \left(\theta \right)\ }=h/\sqrt{x^2+h^2}$ and $dQ=\lambda dx$, we conclude that the $y$-component of the infinitesimal electric field $d\overrightarrow{E}$ is equal to
dE_y=\frac{kdQ}{x^2+h^2}\cdot {\mathrm{cos} \left(\theta \right)\ }=\frac{\lambda kh}{{\left(x^2+h^2\right)}^{3/2}}dx
To find the magnitude $E_y$ of the electric field, we integrate $dE_y$ over $x$ from $x=-L/2$ to $x=L/2$ which yields
\begin{aligned} E_y&=\int^{L/2}_{-L/2}{\frac{\lambda kh}{{\left(x^2+h^2\right)}^{3/2}}dx} \\ \\ &=\lambda kh\cdot {\left[\frac{x}{h^2\sqrt{x^2+h^2}}\right]}^{L/2}_{-L/2} \\ \\ &=\frac{\lambda k}{h}\left(\frac{L}{2\sqrt{h^2+L^2/4}}-\frac{-L}{2\sqrt{h^2+L^2/4}}\right) \\ \\ &=\frac{\lambda kL}{h\sqrt{h^2+L^2/4}} \end{aligned}
The electric field created by the finite length wire at point $P$ is equal to
\boxed{\overrightarrow{E}=\frac{\lambda kL}{h\sqrt{h^2+L^2/4}}\hat{y}=\frac{kQ}{h\sqrt{h^2+L^2/4}}\hat{y}}
Note: we used the following antiderivative in the calculation above
\int{\frac{dx}{{\left(x^2+a^2\right)}^{3/2}}}=\frac{x}{a^2\sqrt{x^2+a^2}}