【发布时间】:2010-08-19 20:44:58
【问题描述】:
我不知道 JSP。我已经编写了下面的 Java JDBC 代码,它必须集成到 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();
}
}
}
最初,我的任务是创建一个文本框并将用户在其中输入的值分配给上面代码中的 String 命名链接。
请告知如何为此构建 JSP 程序。另外,请让我知道是否要对上面的 Java 代码进行任何更改以集成到 JSP 中,或者我可以将整个程序包含在 <% content %> 中。
【问题讨论】:
-
你好...你好...那里有人...回声???
-
对不起……我能理解……不再重复。谢谢你的回答..