52,792
社区成员




package myServlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class CheckServlet extends HttpServlet{
public static final String DRIVER="oracle.jdbc.driver.OracleDriver";
public static final String URL="jdbc:oracle:thin:@127.0.0.1:1521:ORCL";
public static final String USER="scott";
public static final String PASS="simon";
public static void main(String[] args) {
Connection connection=null;
PreparedStatement statement = null;
ResultSet set=null;
System.out.println(true);
try {
Class.forName(DRIVER);
connection=DriverManager.getConnection(URL,USER,PASS);
System.out.println("@@@@@@@@@@@@@@");
statement=connection.prepareStatement("select * from ajaxmember where mid=?");
statement.setString(1, "simon");
set=statement.executeQuery();
while (set.next()) {
System.out.println(set.getString(1));
}
} catch (Exception e) {
e.printStackTrace();
// TODO: handle exception
}finally{
try {
set.close();
statement.close();
connection.close();
} catch (Exception e2) {
// TODO: handle exception
}
}
}
public void doPost(HttpServletRequest req,HttpServletResponse resp) throws IOException{
req.setCharacterEncoding("GBK");
resp.setContentType("text/html");
PrintWriter out=resp.getWriter();
String userid=req.getParameter("userid");
System.out.println(userid);
String sql="select count(mid) from ajaxmember where mid=?" ;
System.out.println(sql);
Connection connection=null;
PreparedStatement statement = null;
ResultSet set=null;
try {
Class.forName(DRIVER);
connection=DriverManager.getConnection(URL,USER,PASS);
System.out.println("*****************");
statement=connection.prepareStatement(sql);
statement.setString(1, userid);
set=statement.executeQuery();
while (set.next()) {
if(set.getInt(1)>0){
System.out.println("false");
out.println("false");
}else {
System.out.println("true");
out.println("true");
}
}
out.close();
} catch (Exception e) {
e.printStackTrace();
// TODO: handle exception
}finally{
try {
statement.close();
set.close();
} catch (Exception e2) {
e2.printStackTrace();
// TODO: handle exception
}
}
}
public void doGet(HttpServletRequest req,HttpServletResponse resp) throws IOException{
this.doGet(req, resp);
}
}