I tried creating threaded class seperately as a java program. But it creates one error.
My code is as follows
--------------------------------------------------------------------------------------------------------------------
package dbs;
import java.io.*;
import java.lang.*;
import java.sql.*;
public class Change implements Runnable
{
public void run()
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con;
Statement st=con.createStatement();
String sql="select * from temp";
ResultSet rs;
try
{
con=DriverManager.getConnection("jdbc:odbc:vr");
rs=st.executeQuery(sql);
if(rs.next())
{
if(rs.getString(1)=="ok")
{
st.executeUpdate("Update temp set id='cancel'");
response.sendRedirect("test1.jsp");
}
}
}
catch(SQLException e1)
{
// System.out.println(e1);
}
catch(InterruptedException e2)
{
}
}
}
--------------------------------------------------------------------------------------------------------------------
When compiling it produces the following error
--------------------------------------------------------------------------------------------------------------------
D:\SADIQ\JSP\DBS>javac Change.java
Change.java:25: cannot resolve symbol
symbol : variable response
location: class dbs.Change
response.sendRedirect("test1.jsp");
^
1 error
--------------------------------------------------------------------------------------------------------------------
Bur I have to redirect the page if the value of the field changes...
Do you know why this error occurs and the way to avoid this..
Thanks for your interest
By
Sadiq
That will not work! The response object is available in the JSP not in the thread.
- if(rs.getString(1)=="ok")
wont work too. When making comparisons use the .equals method. == compares equality of memory locations which is not what you want to compare here.
The thread class and the JSP must be separate files. Is this the thread that is supposed to be checking for changes in the database?