改成这样测试
Connection con=null;
Statement sql=null;
ResultSet rs=null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e) {}
try {
con=DriverManager.getConnection("jdbc:odbc:sun","sa","sa");
sql=con.createStatement();
rs=sql.executeQuery("select 航程 from 国内航班");
while(rs.next());
{
out.print(rs.getInt("航程"));
}
}catch(SQLException e) {ex.printStackTrace () ;}
finally{
if(conn!=null){
try{
conn.close();
}catch(SQLException e){}
}
}
如果不用ODBC你要将相应数据库的驱动复制到WEB-INF/lib下,上面的程序也要修改:
Class.forName的参数改成对应驱动程序,getConnection的参数也要改,如果你用的是SQLServer 2000,在它的驱动程序文档中有这些内容
Connection con=null;
Statement sql=null;
ResultSet rs=null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e) {}
try {
con=DriverManager.getConnection("jdbc:odbc:sun","sa","sa");
sql=con.createStatement();
rs=sql.executeQuery("select 航程 from 国内航班");
while(rs.next());
{
out.print(rs.getInt("航程"));
}
}catch(SQLException e) {ex.printStackTrace () ;}
finally{
if(conn!=null){
try{
conn.close();
}catch(SQLException e){}
}
}
如果不用ODBC你要将相应数据库的驱动复制到WEB-INF/lib下,上面的程序也要修改:
Class.forName的参数改成对应驱动程序,getConnection的参数也要改,如果你用的是SQLServer 2000,在它的驱动程序文档中有这些内容
Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver" );
cn = DriverManager.getConnection( "jdbc:microsoft:sqlserver://MyDbComputerNameOrIP:1433;databaseName=master", sUsr, sPwd ); ODBC
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );
Connection cn = DriverManager.getConnection( "jdbc:odbc:" + sDsn, sUsr, sPwd );
该为con=DriverManager.getConnection("jdbc:odbc:sun");
试试