当前位置: 代码迷 >> Java相关 >> 请教数据连接错哪了,或者如何打印出异常提示
  详细解决方案

请教数据连接错哪了,或者如何打印出异常提示

热度:3349   发布时间:2013-02-25 21:47:31.0
请问数据连接哪里错了,或者怎么打印出错误提示
我是放了JAR包的。

Java code
package com.nong;import javax.servlet.*;import javax.servlet.http.*;import java.io.*;import java.sql.*;public class Lgcl extends HttpServlet {public void doGet(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException{   res.setContentType("text/html;charset=gbk");  PrintWriter pw=res.getWriter();  Connection ct=null;  Statement sm=null;  ResultSet rs=null;  pw.println("aaa");  try{  String u=req.getParameter("username");  String p=req.getParameter("passwd");  Class.forName("com.microsoft.jdbc.sqlserver.SqlserverDriver");  ct=DriverManager.getConnection("jdbc:microsoft:sqlserver://127.0.0.1:1434;DatabaseName=Mybase","sa","long");  sm=ct.createStatement();  rs=sm.executeQuery("select * from user where users='"+u+"' and pwd='"+p+"'");  if(rs.next())  {      pw.println("登录成功");  }  else  {      pw.println("登录失败");  }      }  catch(Exception e)  {      e.printStackTrace();  }  finally  {      try{          if(rs!=null){rs.close();}          if(sm!=null){sm.close();}          if(ct!=null){ct.close();}          }      catch(Exception e)          {              e.printStackTrace();          }        }}public void doPost(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException{    this.doGet(req,res);}    }


------解决方案--------------------------------------------------------
ct=DriverManager.getConnection("jdbc:microsoft:sqlserver://127.0.0.1:1434;DatabaseName=Mybase","sa","long");
url写错了
  相关解决方案