BlogJava-天涯人http://www.blogjava.net/heyibo213/zh-cnFri, 20 Jun 2025 01:32:33 GMTFri, 20 Jun 2025 01:32:33 GMT60操作SQL Server数据库的一个简单程序http://www.blogjava.net/heyibo213/archive/2007/03/24/106029.htmlheyiboflyheyiboflySat, 24 Mar 2007 03:04:00 GMThttp://www.blogjava.net/heyibo213/archive/2007/03/24/106029.htmlhttp://www.blogjava.net/heyibo213/comments/106029.htmlhttp://www.blogjava.net/heyibo213/archive/2007/03/24/106029.html#Feedback0http://www.blogjava.net/heyibo213/comments/commentRss/106029.htmlhttp://www.blogjava.net/heyibo213/services/trackbacks/106029.htmlimport java.sql.*;

public class sqlOperate
{
 private Connection con;
 
 public void connection()  
 {
  try 
  {
     String url = "jdbc:odbc:LocalServer";
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
     con = DriverManager.getConnection(url,"sa","");
  }
  catch(Exception e)
  {
   System.out.println("没有连接!");
  }
 }
 
 public void select()
 {  
          try
          {
           Statement sel = con.createStatement();
           ResultSet rs;
            rs = sel.executeQuery("select * from student");  
           while(rs.next())
            {
              System.out.println(rs.getString("sno")+" "+rs.getString("age"));
             }
          }
         catch(Exception e)
         {
          System.out.println("查询出错");
          }
 }
 
 public static void main(String[] args)
 {
  sqlOperate a = new sqlOperate();
  a.connection();
         a.select();
 }
}



heyibofly 2007-03-24 11:04 发表评论
]]>