日期:2014-05-20  浏览次数:20780 次

初学JDBC遇到问题,代码帖出,请高手帮忙指点,谢谢
import   java.sql.*;
import   java.net.*;


public   class   Insert{
public   static   void   main(String[]   args){
    String   url= "jdbc:microsoft:sqlserver://localhost:1433;User=sa;Password=public;DatabaseName   =Northwind ";

    //sql语句;
    String   query   =   "Select   *   from   firsttable ";

    try{

                          Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver ");

Connection   con   =   DriverManager.getConnection(url);

Statement   stmt   =   con.createStatement();

ResultSet   rs   =   stmt.executeQuery(query);

dispResultSet(rs);

rs.close();

stmt.close();

con.close();
    }
    catch(SQLException   ex){

System.out.println( "\n***SQLException   caught***\n ");

while(ex   !=   null){
System.out.println( "SQLState: "   +   ex.getSQLState());
System.out.println( "Message: "   +   ex.getMessage());  
System.out.println( "Vendor:   "   +   ex.getErrorCode());    
ex   =   ex.getNextException();
System.out.println( " ");
    }
    }
    catch(java.lang.Exception   ex){
ex.printStackTrace();
    }
}//main

    private   static   void   dispResultSet(ResultSet   rs)                                   throwsSQLException{
int   i;

ResultSetMetaDate   rsmd   =   rs.getMetaDate();

int   numCols   =   rsmd.getColumnCount();

for(i   =   1;   i   <=   numCols;   i++){
if(i   >   1)   System.out.print( ",     ");
System.out.print(rsmd.getColumnLabel(i));
}//for
System.out.print( "   ");
System.out.print( "   ");

boolean   more   =   rs.next();

while(more){

for(i   =   1;i   <=   numCols;i++){
if(i   >   1)System.out.print( ",     ");
System.out.print(rs.getString(i));
}
System.out.println( " ");
more   =   rs.next();
}//while
    }
}


提示错误是:cannot   resolve   symbol
                      symbol:class   ResultSetMetaDate   rsdm   =   rs.getMetaDate();




------解决方案--------------------
ResultSetMetaDate ??
是ResultSetMetaData吧!!
------解决方案--------------------
int i;

java.sql.ResultSetMetaData rsmd = rs.getMetaData();

int numCols = rsmd.getColumnCount();

for(i = 1; i <= numCols; i++)
{
if(i > 1)
System.out.print( ", ");