I dont know JSP. I have written the below Java JDBC code which must be integrated in JSP.
import java.net.URL;
import java.net.URLConnection;
import java.sql.*;
public class searchlink{
public static void main(String args[]) throws Exception {
Connection con=null;
Statement stmt=null;
Statement stmtR=null;
String link="http://www.topix.com/rss/city/ellensburgwa";
String source="Sample";
if(con==null){
SQLConnection.setURL("jdbc:sqlserver://192.168.2.53\\SQL2005;user=sa;password=365media;DatabaseName=LN_ADWEEK");
con=SQLConnection.getNewConnection();
stmt=con.createStatement();
stmtR=con.createStatement();
}
ResultSet rs;
boolean hasRows=false;
rs=stmt.executeQuery("select url from urls where url='"+link+"'");
while(rs.next()){
hasRows=true;
//String mem=rs.getString(1);
System.out.println("This URL already exists in DB");}
if (!hasRows)
{
PreparedStatement insertUrlStatement = con.prepareStatement("INSERT INTO urls VALUES(?, ?, ?, ?, ?)");
insertUrlStatement.setInt(1, 21211);
insertUrlStatement.setString(2, link);
insertUrlStatement.setString(3, source);
insertUrlStatement.setInt(4, 1);
insertUrlStatement.setInt(5, 0);
insertUrlStatement.executeUpdate();
}
}
}
Initially, my task is to create a text box and assign the value the user enters in it to the String named link which is in the code above.
Kindly advise how to build a JSP program for that. Also, please let me know whether any changes are to be made in the Java code above for integrating in JSP or I can just include the whole program inside <% content %>
.