ÍƼö¸ø³õѧÕߣºÍ¨¹ýODBC?JDBCºÍSQLרÓÃJDBCÇý¶¯ÊµÏÖ¼òµ¥µÄÊý¾Ý

ÍƼö¸ø³õѧÕߣºÍ¨¹ýODBC?JDBCºÍSQLרÓÃJDBCÇý¶¯ÊµÏÖ¼òµ¥µÄÊý¾Ý - Ó¦ÓÃÈí¼þ - µçÄԽ̳ÌÍø

ÍƼö¸ø³õѧÕߣºÍ¨¹ýODBC?JDBCºÍSQLרÓÃJDBCÇý¶¯ÊµÏÖ¼òµ¥µÄÊý¾Ý

ÈÕÆÚ£º2007-07-11   ¼ö£º
ͨ¹ýSQL2000רÓÃÇý¶¯·ÃÎʼòµ¥µÄSQL2000ÍøÂçÊý¾Ý¿â£¡¡°¡±ÎÞÐëÉèÖÃODBC¡°¡±=======================================================================Ä¿Ç°ÓëJDBCÓйصÄÇý¶¯ÓÐ4ÖÐÀàÐÍ£¡¶ÁÕß¿ÉÒÔÉÏÍø²éѯÏà¹Ø×ÊÁÏ£¡========================================================import java.sql.*;import java.net.*;public class sql_data{ public static void main(String args[]){try{// SQL2000רÓÃÇý¶¯Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); Connection con= DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433","pdfjn5189","pdfjnb511"); Statement sta1=con.createStatement(); ResultSet set1=sta1.executeQuery(" select b511.* from b511"); while(set1.next()) {System.out.println(set1.getString(1) set1.getString(2) set1.getString(3)); }set1.close();con.close(); }catch(ClassNotFoundException e) //²¶×½----¼ÓÔØÇý¶¯³öÏÖÒì³£ { e.getMessage();}catch(SQLException e){e.getMessage(); }}}===========================²éѯ½á¹û£ºÐìXX °²»Õ ¼ÆËã»úÈí¼þÍôXX ½­Î÷ ¼ÆËã»úÈí¼þÉϹ٠½­Î÷ ¼ÆËã»úÑî XX ½­Î÷ ¼ÆËã»úÈí¼þÅíXX ºþ±± ¼ÆËã»úÈí¼þÐìXX ½­Î÷ ¼ÆËã»úÈí¼þPress any key to continue...========================================================================Ìáʾ£º jdbc.odbcÇŽÓÆ÷ ¡°¡±ÐèÒªÉèÖÃODBCÊý¾ÝÔ´¡°¡±=======================================================================import java.sql.*;import java.net.*;public class data_access{ public static void main(String args[]) { String insert1,insert2; try { Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");Connection cn =DriverManager.getConnection("jdbc:odbc:data_access","","");Statement sql=cn.createStatement();// ´´½¨Ò»¸öSQLÓï¾ä¶ÔÏó£¡ ¿ÉÒÔÖظ´ÀûÓÃ!//-----------------------------------------------------------------------------//Êý¾Ý¸üУ¡//sql.executeUpdate("insert into studentbase(ѧºÅ,ÐÕÃû,ÄêÁä,ÐÔ±ð,ϵÃû) values(¡ä02610387¡ä,¡äÉϹ١ä,¡ä20¡ä,¡äÄСä,¡ä¼ÆËã»úϵ¡ä)"); // ×¢Òâ (ѧºÅ,ÐÕÃû,ÄêÁä,ÐÔ±ð,ϵÃû) ²»ÄÜÊ¡ÂÔ£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡1 // sql.executeUpdate(" alter table studentbase add column ±ÏÒµÖÐѧ varchar(30)"); // sql.executeUpdate(" create table classinfo( ¿Î³ÌÃû³Æ char(20),¿Î³Ì´úºÅ char(8),ÈονÌʦ char(15)"); //--------------------------------------------------------------------------ResultSet set=sql.executeQuery(" select studentbase.* from studentbase");System.out.println("------------------------------------------------"); while(set.next()){ System.out.println(set.getString(1) " " set.getString(2) " " set.getString(3) " " set.getString(4) " " set.getString(5) " " set.getString(6));} //---------------------------------------------------------------------------------------System.out.println("------------------------------------------------"); ResultSet set1= sql.executeQuery(" select studentbase.ÐÕÃû,studentaddress.EmailµØÖ· from studentbase,studentaddress where studentbase.ѧºÅ= studentaddress.ѧºÅ "); while(set1.next()){ System.out.println(set1.getString(1) " " set1.getString(2));} //----------------------------------------------------------------------------------------- cn.close();}catch(ClassNotFoundException e) //²¶×½----¼ÓÔØÇý¶¯³öÏÖÒì³£{ e.printStackTrace();}catch(SQLException e){e.getMessage(); }}} ================ Êä³ö½á¹û£º ------------------------------------------------200166001 ÕÔÃ÷ 20 Å® ¼ÆËã»úϵ200166002 Ç®Ïþ 21 ÄÐ ÎïÀíϵ200166003 Ëﳿ 19 ÄÐ ¼ÆËã»úϵ200166004 Åí¾¢ËÉ 21 ÄÐ ¼ÆËã»úϵ200166005 Áõ·ê 21 ÄÐ ¼ÆËã»úϵ200166006 ¶­½á 20 ÄÐ Ó¢Óïϵ200166007 ÕÔÇ¿ 20 ÄÐ Õþ·¨Ïµ02610387 ÉϹ٠20 ÄÐ ¼ÆËã»úϵ------------------------------------------------ÕÔÃ÷ [email protected]Ç®Ïþ [email protected]Ëﳿ [email protected]Åí¾¢ËÉ [email protected]Áõ·ê [email protected]¶­½á [email protected]ÕÔÇ¿ [email protected] any key to continue...
±êÇ©£º