连接sql server问题(急)
小妹帮别人问的。据他本人所说,用记事本编好了代码,然后再IE上调试。
在用ODBC连接成功,而用JDBC连接不成功。安装了sql驱动
jsp(selectUserTable2.jsp)代码如下:
<%@ page contentType= "text/html;charset=GB2312 " %>
<%@ page import= "java.sql.* " %>
<HTML>
<BODY>
<% Connection con;
Statement sql;
ResultSet rs;
try
{
Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver ");
}
catch(
ClassNotFoundException e)
{
out.print( "类找不到! ");
}
try
{
con=DriverManager.getConnection( "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=testDatabase ", "sa ", "6599996 ");
sql=con.createStatement();
rs=sql.executeQuery( "SELECT * FROM userTable ");
out.print( " <Table Border> ");
out.print( " <TR> <td colspan=8 align=center> 用户数据 </td> </tr> ");
out.print( " <TR> ");
out.print( " <Td width=100 > "+ "用户ID号 ");
out.print( " <Td width=50 > "+ "用户名 ");
out.print( " <Td width=100> "+ "用户真实姓名 ");
out.print( " <Td width=50> "+ "年龄 ");
out.print( " <Td width=50> "+ "性别 ");
out.print( " <Td width=100> "+ "联系地址 ");
out.print( " <Td width=100> "+ "联系电话 ");
out.print( " <Td width=100> "+ "添加时间 ");
out.print( " </TR> ");
while(rs.next())
{ out.print( " <TR> ");
out.print( " <TD > "+rs.getLong(1)+ " </TD> ");
out.print( " <TD > "+rs.getString(2)+ " </TD> ");