java³ÌÐòÁ¬½ÓSQlServerµÄÎÊÌâ - Java / Java SE
import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class QueryTest
{
private Connection con;
public static void main(String [] atgs)
{
QueryTest test = new QueryTest();
Connection con = test.getConnection();
String sql = "select * from Student";
test.getStudent(con, sql);
}
public void getStudent(Connection con, String sql)
{
try
{
Statement st = con.createStatement(); //ÉêÇë»á»°
ResultSet rs = st.executeQuery(sql); //»ñµÃ²éѯ¼Ç¼¼¯
while( rs.next() )
{
String name = rs.getString( "ÐÕÃû" );
String number = rs.getString( "ѧºÅ" );
String sex = rs.getString( "ÐÔ±ð" );
Date date = rs.getDate( "ÉúÈÕ" );
String spe = rs.getString( "רҵ" );
String address = rs.getString( "¼®¹á" );
System.out.println( "\nÐÕÃû£º " + name + "\tѧºÅ" + number + "\tÐÔ±ð" + sex
+ "\tÉúÈÕ" + date + "\tרҵ" + spe + "\t¼®¹á" + address );
}
st.close();
con.close();
}
catch( SQLException e )
{
Ïà¹ØÎÊ´ð£º
ÎÒµÄjava applet ǶÈëhtmlºóÎÞ·¨ÏÔʾ£¬¶øÓÃappletviewerÏÔʾÕý³£ÎªÊ²Ã´£¬»¹ÓоÍÊÇÓÃhtml converterת»¯ºó¿ÉÒÔÏÔʾ£¬ÎªÊ²Ã´£¿Çë´óÏÀ´Í½Ì£¡
HTML code:
<HTML>
<HEAD>
<TITLE>TEST.HTML< ......
´ó¼ÒºÃ£¬ÎÒÃǽüÆÚÕÐƸȫְ¡¢¼æÖ°¿ª·¢¹¤³Ìʦ£¬È«Ö°¹¤³Ìʦ¹¤×÷µØµãÖ÷ÒªÊÇÉîÛÚ£¬¼æÖ°¹¤³Ìʦ±¾ÈË¿ÉÔÚÉîÛÚ£¬Ò²¿ÉÒÔÔÚÒìµØͨ¹ýÔ¶³ÌÐͬ¿ª·¢µÄ·½Ê½¿ªÕ¹¹¤×÷£¬ºÏ×÷·½Ê½¿É¹²Í¬É̶¨¡£
ְλE601£ºJava ¹¤³Ìʦ£¨Web ¿ ......
ÎÒÏëÓÃJavaдһ¸ö³ÌÐò£¬¾ÍÊÇÎÒÏëÔÚÔËÐдúÂëºó£¬ÔÚÖ¸¶¨µÄʱ¼ä´ò¿ªÄ³³ÌÐò£¬ÀýÈçÎÒÔËÐдúÂëºó£¬½²ÔÚ12£º00´ò¿ª"D:\Program Files\Tencent\QQ2009\Bin\QQ.exe"Õâ¸ö³ÌÐò£¬Çó¸ßÈËÖ¸µã¡£»¹ÓпÉÄܵĻ°ÔÚÖ¸¶¨µÄʱ¼ä ......
public class Student{
//×ֶεĶ¨Òå
private String _number; //ѧºÅ
private String _name; //ÐÕÃû
private   ......
ÔÚSqlServerÖÐÈçºÎ²é¿´ÀúÊ·ÉÏÖ´ÐеĴ洢¹ý³ÌµÄÐÅÏ¢ÄØ£¬È磺´«Èë²ÎÊý£¬Ö´ÐÐʱ¼äµÈµÈ¡£Èç¹û²»Äܲ鿴ÀúÊ·¼Ç¼£¬ÊÇ·ñ¿ÉÒÔ×Ô¼ºÐ´´¥·¢Æ÷Ö®ÀàµÄ£¬È˹¤¿ØÖÆÄØ£¬ÔÚOracleÀïÃæÓж¯Ì¬ÊÓͼ¿ÉÒÔËæʱ²é¿´ÀúÊ·Ö´ÐеÄsqlÓï¾ä£¬SqlSer ......