我是初学者,试图在页面里连接数据库,用的是sql server 2000,连接jdbc需要的3个jar包也引入了,为什么还是老提示:
java.sql.SQLException: No suitable driver found for jdbc:microsoft:sqlserver://127.0.0.1:1433:databaseName=users连接代码如下: try
{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
System.out.println("加载驱动成功"); Connection ct=DriverManager.getConnection ("jdbc:microsoft:sqlserver://127.0.0.1:1433:databaseName=users","sa","000000");
System.out.println("得到连接成功");
PreparedStatement ps=ct.prepareStatement("select userCode from userInfo where username='"+u+"'");
ResultSet rs=ps.executeQuery();
if(rs.next())
{
if(rs.getString(3).equals(p))
response.sendRedirect("welcome.jsp");
else
response.sendRedirect("login.jsp");
}
else
response.sendRedirect("login.jsp");
}
catch(Exception e)
{
e.printStackTrace();
}
程序貌似只能执行到这一句,就不动了。
Connection ct=DriverManager.getConnection("jdbc:microsoft:sqlserver://127.0.0.1:1433:databaseName=users","sa","000000");
java.sql.SQLException: No suitable driver found for jdbc:microsoft:sqlserver://127.0.0.1:1433:databaseName=users连接代码如下: try
{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
System.out.println("加载驱动成功"); Connection ct=DriverManager.getConnection ("jdbc:microsoft:sqlserver://127.0.0.1:1433:databaseName=users","sa","000000");
System.out.println("得到连接成功");
PreparedStatement ps=ct.prepareStatement("select userCode from userInfo where username='"+u+"'");
ResultSet rs=ps.executeQuery();
if(rs.next())
{
if(rs.getString(3).equals(p))
response.sendRedirect("welcome.jsp");
else
response.sendRedirect("login.jsp");
}
else
response.sendRedirect("login.jsp");
}
catch(Exception e)
{
e.printStackTrace();
}
程序貌似只能执行到这一句,就不动了。
Connection ct=DriverManager.getConnection("jdbc:microsoft:sqlserver://127.0.0.1:1433:databaseName=users","sa","000000");
url = jdbc:jtds:sqlserver://127.0.0.1/DB名;jar包地址是:
http://www.java2s.com/Code/Jar/j/Downloadjtds121jar.htm
这样是加入了classpath么?