Prepositions affect the case of the noun after them, and two-way prepositions can either put this noun into the dative or the accusative, depending on if there is movement in the sentence or not.
Examples of two-way prepositions are:
in
auf
unter
vor
neben
zwischen
an
Most of the time, these prepositions put the noun into the dative. If movement is involved, however, they put the noun into the accusative.
Here are two examples of similar sentences using the preposition "in", one of which uses the dative and one of which uses the accusative.
Ich gehe in die Schule.
Die Maus wohnt in der Schule.
Here, "I" am going to school, so I am moving because I am travelling to school, whereas the mouse lives there all the time and isn't moving. Therefore, "school" is in the accusative in the sentence involving "me", and it's in the dative in the sentence with the mouse.
Warning! Watch out for the verb "bleiben", which means "to stay" - this verb makes the sentence act as though there is movement, even though this verb means the exact opposite!