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¿ª·¢¹¤³Ìʦ
ְλÃèÊö£º
1¡¢°´USECASE½øÐÐÒµÎñÐèÇó·ÖÎöºÍÈí¼þ¸ÅÒªÉè¼Æ£»
2¡¢½øÐÐÈí¼þÏêϸÉè¼ÆºÍ±àÂëʵÏÖ£¬È·±£ÐÔÄÜ¡¢ÖÊÁ¿ºÍ°²È«£»
3¡¢Î¬»¤ºÍÉý¼¶ÏÖÓÐÈí¼þ²úÆ·£¬¿ìËÙ¶¨Î»² ......
ÎÒµÄjava applet ǶÈëhtmlºóÎÞ·¨ÏÔʾ£¬¶øÓÃappletviewerÏÔʾÕý³£ÎªÊ²Ã´£¬»¹ÓоÍÊÇÓÃhtml converterת»¯ºó¿ÉÒÔÏÔʾ£¬ÎªÊ²Ã´£¿Çë´óÏÀ´Í½Ì£¡
HTML code:
<HTML>
<HEAD>
<TITLE>TEST.HTML< ......
´ó¼ÒºÃ£¬ÎÒÃǽüÆÚÕÐƸȫְ¡¢¼æÖ°¿ª·¢¹¤³Ìʦ£¬È«Ö°¹¤³Ìʦ¹¤×÷µØµãÖ÷ÒªÊÇÉîÛÚ£¬¼æÖ°¹¤³Ìʦ±¾ÈË¿ÉÔÚÉîÛÚ£¬Ò²¿ÉÒÔÔÚÒìµØͨ¹ýÔ¶³ÌÐͬ¿ª·¢µÄ·½Ê½¿ªÕ¹¹¤×÷£¬ºÏ×÷·½Ê½¿É¹²Í¬É̶¨¡£
ְλE601£ºJava ¹¤³ÌÊ ......
public class Student{
//×ֶεĶ¨Òå
private String _number; //ѧºÅ
private String _name; //ÐÕÃû
private   ......