🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: cn.bbs.comp.lang.java
Article #21622

����й�jdbc����sql server������

#21622
From: ����¥
Date: Wed, 26 Nov 2003 02:01
72 lines
3354 bytes
������jdbc-odbc������,����odbc�������ӿ��Գɹ�,��ݿ���Ϊhehe,����ֻ��һ����,
����Ϊuser,������ֶ�,���ͷֱ�Ϊ:smallint,varchar,varchar,�Ұ��������access��

�ݿ�,��ͬ��Ĵ��������ʾ����,������sql serverȴʲô���ݶ�������ʾ,���λ����
��æ,��ʤ�м�,���õ�Դ��������:
import java.awt.*;
import java.sql.*;

public class jTest {
   public static void main(String args[])
   {    
        String url="jdbc:odbc:hehe";
        Connection con=null;
        Statement  sm=null;
        ResultSet  rs=null;
        
         try
         {
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
         }
         catch(Exception e)
         {
                System.out.println("cannot create jdbcOdbcDriver");
                return;
         }
         
         
         
         try
         {
                
                con=DriverManager.getConnection(url,"sa","");
                
                sm=con.createStatement();
          //sm.executeUpdate("delete from guestbook where content=''");
          //sm.executeUpdate("insert  into user  values('1004','hehe','234') 
");
                
                rs=sm.executeQuery("select * from user");
                
                while(rs.next())
                  {
                    short  user_id=rs.getShort("id");
                        String  user_name=rs.getString("name");
                        String  user_pass=rs.getString("password");
                    System.out.println("the user id is: "+user_id );
                        System.out.println("the user room is "+ user_name);
                        System.out.println("the user day is "+ user_pass);
                        
                  }
                  
                  }
                 catch(Exception e)
                 {}
                 
                 finally
                  {
                        try
                        {
                                rs.close();
                                sm.close();
                                con.close();
                        }
                         catch(Exception e)
                         {}
                        }
                  }
         }
                    

--
�� ��Դ:������δ��վ bbs.pku.edu.cn��[FROM: 210.34.50.72]
Technical Details
Message-ID: <49PO5d$ASP@bbs.pku.edu.cn>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!feed2.newsreader.com!newsreader.com!maily.cic.tsinghua.edu.cn!news.happynet.org!PKU

Show Full Headers
Complete Article Headers
X-Google-Language: Chinese,GB
X-Google-Thread: f6cb0,654383fb952bb5f7,start
X-Google-Attributes: gidf6cb0,public
X-Google-ArrivalTime: 2003-11-25 18:02:08 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!feed2.newsreader.com!newsreader.com!maily.cic.tsinghua.edu.cn!news.happynet.org!PKU
From: folwind@bbs.pku.edu.cn (����¥)
Newsgroups: cn.bbs.comp.lang.java
Subject: ����й�jdbc����sql server������
Date: 26 Nov 2003 02:01:21 GMT
Organization: ����δ��վ
Message-ID: <49PO5d$ASP@bbs.pku.edu.cn>
Mime-Version: 1.0
Content-Type: text/plain; charset="gb2312"
Content-Transfer-Encoding: 8bit
X-Filename: Java/M.1069811991.A
Lines: 72