Ya me lo había puesto m1t$u, lo intente de cuarenta formas, y no pude. Me quedé ahí:
Código
if (e.getSource()==boton2) { Class.forName("com.mysql.jdbc.Driver"); Connection conexion = DriverManager.getConnection("jdbc:mysql://localhost/bd1", "root", ""); Statement st = conexion.createStatement(); ResultSet rs = st.executeQuery("SELECT * FROM codigo where "+textfield1+"= '"+codigo+"'"); }
El JTextField se llama: textfield1