我在JSP中尝试了一个代码,其中我有2个数据库n我必须从数据库1中获取一个值,并与另一个数据库中的值进行比较。所有数据都运行良好。即使它在页面上打印。但不能与之相比。
这是我尝试过的代码。
<%@ page import="java.sql.*" %>
<%!
String userName;
int marks;
int i=3;
String obj1,obj2;
int whileCount=0;
%>
<%
userName=request.getParameter("u_n");
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con1=DriverManager.getConnection("jdbc:odbc:login_dsn");
Connection con2=DriverManager.getConnection("jdbc:odbc:model_ans");
Statement st1=con1.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
String query="select * from login where id="+userName;
ResultSet res1=st1.executeQuery(query);
Statement st2=con2.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
ResultSet res2=st2.executeQuery("select * from model_ans");
res1.first();
res2.first();
i=3;
marks=0;
do
{
obj1=res1.getString(i);
obj2=res2.getString(2);
whileCount++;
out.println(obj1+" "+obj2+" " );
if(obj1.equals(obj2)==false)
marks++;
i=i+1;
}while(res2.next());
out.println("total while count:"+whileCount);
whileCount=0;
out.println("Total marks:"+marks);
con1.close();
con2.close();
}
catch(Exception e)
{
out.println(e.toString());
}
%>
数据库查询如下:
1.First DB:
create table login(id number,password text,q1 text,q2 text,[upto 30],q3 text);
2.Second DB:
create table model_ans(id number,Ans text);