only you ,下面是我配置的servet和web.xml内容.但是会报错.我对你的
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs";
这条语句理解得可能有点问题,拜托你看看,那个1433是什么端口号,sqlserver还是tomcat.
那个ip是我tomcat的ip,还是数据库存放主机的ip.如果我能够配通,我一定将分数全部赠送.
servlet内容:
package TestPackage;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class SqlserverTest extends ClassLoader {
public static void main(String args[]) throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String sourceURL="jdbc:micorsoft:sqlserver://40.1.40.14:1433;DatabaseName=baseinfo";
String user="mike";
String password="mike";
Connection conn;
conn = DriverManager.getConnection(sourceURL, user, password);
System.out.println("Startomg ok!");
conn.close();
}
}
web.xml相关内容:
<servlet>
<servlet-name>SqlServlet</servlet-name>
<servlet-class>TestPackage.SqlserverTest</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SqlServlet</servlet-name>
<url-pattern>/SqlPage</url-pattern>
</servlet-mapping>
我输入http://127.0.0.1:8080/Test/SqlPage
报错如下:
HTTP Status 503 - Servlet SqlServlet is currently unavailable
--------------------------------------------------------------------------------
type Status report
message Servlet SqlServlet is currently unavailable
description The requested service (Servlet SqlServlet is currently unavailable) is not currently available.
--------------------------------------------------------------------------------
Apache Tomcat/4.1.24