=======================================sqlserver测试=============================================
import java.sql.*;
public class sql_server_test{
public static void main(String[] args)
{
String driverName="com.microsoft.sqlserver.jdbc.SQLServerDriver";
String dbURL="jdbc:sqlserver://localhost:1433;DatabaseName=student";
String userName="sa";
String userPwd="root";
try
{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
System.out.println("加载驱动成功!");
}catch(Exception e){
e.printStackTrace();
System.out.println("加载驱动失败!");
}
try{
@SuppressWarnings("unused")
Connection dbConn=DriverManager.getConnection(dbURL,userName,userPwd);
System.out.println("连接数据库成功!");
}catch(Exception e)
{
e.printStackTrace();
System.out.print("SQL Server连接失败!");
}
}
//这段代码运行正常 但是访问数据库就不行........
===============================================================================================
<%
String driverName="com.microsoft.sqlserver.jdbc.SQLServerDriver";
Class.forName(driverName) ;
String url ="jdbc:microsoft:sqlserver://localhost:1434;Databasename=student";
String userName = "sa";
String userPassword = "root";
Connection conn = DriverManager.getConnection(url,userName,userPassword);
Statement stmt = conn.createStatement();
String sql = "select * from info";
ResultSet rs = stmt.executeQuery(sql);
while(rs.next()){
%>
--------------------------------------------------------------------报错信息 ----------------------------------------------------------------------------------------
HTTP Status 500 - javax.servlet.ServletException: java.sql.SQLException: No suitable driver found for jdbc:microsoft:sqlserver://localhost:1434;Databasename=student
================================================================================================
用的是 D:\Microsoft JDBC Driver 4.0 for SQL Server\sqljdbc_4.0\chs 驱动
[b] myeclipse 2014 tomcat8.0[/b]
------解决思路----------------------
你这么说,我想起来了,当时在学校做JAVA的时候,印象有些地方要求强制加上捕捉异常,不然连编译都不让通过,详情,我想你可以到JAVA版块问下~~