try
{
     int req_id=Integer.parseInt(request.getParameter("id"));
     Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
     Connection con=DriverManager.getConnection("jdbc:odbc:amcdb","","");
     Statement st=con.createStatement();
     ResultSet rs=st.executeQuery("select email from detail where id="+req_id+"");
     String result;
     String to=rs.getString(4);
}

Assign the result of a query to a string using 'next()' with 'while' looping

while (rs.next()) {
        result = rs.getString(1);
    }

A problem with the first code is that result and to are declared inside the try block, so those variables cease to exist as soon as the block is exited. You need to declare them outside the try block if you want to use them outside the try block.

another problem is that the bridge driver has been removed in Java 8 and has been seriously buggy and unsupported for at least a decade in older versions.
Use a real database.

Another problem is that you never properly dispose of your database objects, don't close your connection, etc. etc. which is very bad.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.