主题:java中的sql问题
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.*;
public class XnkMain extends HttpServlet
{
public XnkMain()
{
super();
}
public void destroy()
{
super.destroy();
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
this.doGet(request,response);
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=gsmvmc";
String bb="No...";
ResultSet rs;
String b="123";
try
{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection con=DriverManager.getConnection(url,"sa","");
Statement stmt=con.createStatement();
rs=stmt.executeQuery("select b from zhouling where a='1'");
b=rs.getString(b);
bb="Yes...";
stmt.close();
con.close();
}
catch(java.lang.Exception ex)
{
ex.printStackTrace();
}
String userId=request.getParameter("x1");
out.println("<HTML>");
out.println(" <HEAD><TITLE>数据库连接</TITLE></HEAD>");
out.println(" <BODY>");
out.println(userId+" ");
out.println(bb+" ");
out.println(b);
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}
public void init() throws ServletException
{
}
}
请问一下...我这段代码为什么不能执行sql语句...我搞了一天了还是不知道错在那..[em18]
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.*;
public class XnkMain extends HttpServlet
{
public XnkMain()
{
super();
}
public void destroy()
{
super.destroy();
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
this.doGet(request,response);
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=gsmvmc";
String bb="No...";
ResultSet rs;
String b="123";
try
{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection con=DriverManager.getConnection(url,"sa","");
Statement stmt=con.createStatement();
rs=stmt.executeQuery("select b from zhouling where a='1'");
b=rs.getString(b);
bb="Yes...";
stmt.close();
con.close();
}
catch(java.lang.Exception ex)
{
ex.printStackTrace();
}
String userId=request.getParameter("x1");
out.println("<HTML>");
out.println(" <HEAD><TITLE>数据库连接</TITLE></HEAD>");
out.println(" <BODY>");
out.println(userId+" ");
out.println(bb+" ");
out.println(b);
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}
public void init() throws ServletException
{
}
}
请问一下...我这段代码为什么不能执行sql语句...我搞了一天了还是不知道错在那..[em18]