0
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);
}

Edited by pritaeas: Moved.

4
Contributors
3
Replies
11
Views
3 Years
Discussion Span
Last Post by jwenting
0

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

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

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.

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.