ʹÓÃservletºÍJava Bean·ÃÎÊMySQL
»·¾³: JDK 5.0 + Tomcat 5.5.4
JDK°²×°Â·¾¶: D:\Java\jdk1.5.0_01
Tomcat°²×°Â·¾¶:D:\Tomcat 5.5
ÉèÖû·¾³±äÁ¿(¿ØÖÆÃæ°å->ϵͳ->¸ß¼¶):
java_home=D:\Java\jdk1.5.0_01
path=%JAVA_HOME%\bin
classpath=.;D:\Java\jdk1.5.0_01\lib\dt.jar;D:\Java\jdk1.5.0_01\lib\tools.jar;D:\Tomcat 5.5\common\lib\servlet-api.jar;D:\Tomcat 5.5\common\lib\mysql-connector-java-3.1.6-bin.jar;
ÆäÖÐD:\Tomcat 5.5\common\lib\servlet-api.jarΪTomcatµÄservlet APIʵÏÖ,Ò»¶¨Òª¼ÓÉÏ,²»ÈçÎÞ·¨±àÒëservlet
D:\Tomcat 5.5\common\lib\mysql-connector-java-3.1.6-bin.jar;ÊÇMySQLµÄJDBCÇý¶¯,connect/J 3.1.6,¿Éµ½MySQL¹Ù·½ÍøÕ¾ÏÂÔØ
Tomcat5.5ÐéÄâĿ¼É趨:
D:\Tomcat 5.5\conf\Catalina\localhostÏÂмÓÒ»test.xml
ÄÚÈÝÈçÏÂ:
<Context path="/test" docBase="d:/www" reloadable="true" crossContext="true" debug="0" >
</Context>
d:\www·¾¶½«ÊÇÎÒÃDzâÊÔÍøÕ¾µÄ¸ùĿ¼,ͨ¹ýhttp://localhost:8080/test·ÃÎʸÃÐéÄâĿ¼
d:\wwwϽ¨ÓÐĿ¼WEB-INF,ÏÂÓÐweb.xmlÉèÖÃÎļþ(¿É²Î¿¼D:\Tomcat 5.5\webapps\ROOT\WEB-INF\web.xml),classesĿ¼ºÍlibĿ¼
//Á¬½ÓÊý¾Ý¿âµÄJava BeanÎļþÃûDBConn.java
package zhy.database;
import java.sql.*;
public class DBConn {
public DBConn() {
}
//declare variable
private Connection conn = null;
ResultSet rs = null;
private String server = "127.0.0.1";
private String port = "3306";
private String db = "test";
private String user = "root";
private String pass = "password";
private String drivername="com.mysql.jdbc.Driver";
private String URL="jdbc:mysql://"+server+":"+port+"/"+db+"?user="+user+"&password="+pass;
public Connection getConn(){//get database connection
try{
Class.forName(drivername).newInstance();
conn = DriverManager.getConnection(URL);
}
catch(Exception e){
e.printStackTrace();
}
return this.conn ;
}
public ResultSet executeSQL(String str) {
try{
Statement stmt = conn.createStatement();
rs = stmt.executeQuery(str);
}
catch(Exception e){
e.printStackTrace();
}
return this.rs;
}
}
±àÒëjavac welcome.java,½«±àÒëº
Ïà¹ØÎĵµ£º
ÕⶼÊÇÎÒѧϰJAVAÇ×Éí¾ÀúµÄÐĵ㬽ñÌ컨ÁËÒ»¸ö¶àСʱ×ܽá³öÀ´Ï£Íû¶Ô´ó¼ÒÓÐÒ»¶¨µÄ°ïÖú¡£Èç¹ûÈç×ܽ᲻Í×£¬ÇëÖ¸³öºÍÅúÆÀ£¡ÎªÑ§Ï°JAVAµÄ³õѧÕßÆÌÌõѧϰJAVAµÄµÀ·
Ê×ÏÈ´ó¼ÒÒªÃ÷È·Ò»µã£¬ÍâÃæÕÐƸJAVAµÄ£¬Ö÷ÒªÊÇÖ¸µÄJ2EE£¬Ò²¾ÍÊÇBS½á¹¹£¨ä¯ÀÀÆ÷ºÍ·þÎñÆ÷½á¹¹£©JAVAµÄÖ®ËùÒÔ»ðÆðÀ´ÕæÊÇÒòΪBS½á¹¹£¬²¢²»ÔÚCS½á¹¹£¬ËùÒÔÄÇÖÖ´óÐÍÍøÓÎ ......
21ÌìѧͨJava6 ÏÂÔصØÖ· http://d.download.csdn.net/down/2031000/bolike£¨Ö»ÓÐÔ´´úÂ룩
<<21ÌìѧͨJava 2(µÚ¶þ°æ)>>(ÖÐÓ¢ÎÄ°æPDF)+¸½ÊéÔ´Âë ÏÂÔصØÖ· http://www.zzx8.com/html/c16246.html£¨ËƺõÖÐÓ¢ÎĵIJ»¶ÔÓ¦£¬¿´ÖÐÎÄ»¹ÊÇ¿´Ó¢Îĵģ¿£© ......
µÝ¹éËã·¨Éè¼ÆµÄ»ù±¾Ë¼ÏëÊÇ£º¶ÔÓÚÒ»¸ö¸´ÔÓµÄÎÊÌ⣬°ÑÔÎÊÌâ·Ö½âΪÈô¸É¸öÏà¶Ô¼òµ¥ÀàͬµÄ×ÓÎÊÌ⣬¼ÌÐøÏÂÈ¥Ö±µ½×ÓÎÊÌâ¼òµ¥µ½Äܹ»Ö±½ÓÇó½â£¬Ò²¾ÍÊÇ˵µ½Á˵ÝÍƵijö¿Ú£¬ÕâÑùÔÎÊÌâ¾ÍÓеÝÍƵý⡣
¹Ø¼üҪץסµÄÊÇ£º
£¨1£©µÝ¹é³ö¿Ú
£¨2£©µØÍÆÖð²½Ïò³ö¿Ú±Æ½ü
Àý×Ó:
example£º Çó5µÄ½×³Ë¡£¡£ & ......
ÔÚºÍгµÄÍøÂçÊÀ½çÖУ¬ÓÐÒ»¸öÉñÃصÄÀÖÔ°£¬½ÐCaoLiuÉçÇø£¨ÓÉÓÚºÍг£¬ÓÃÁËÆ´Òô£©£¬ÕâÊÇÒ»¸ö´«ËµµÄËùÔÚ£¬ÆäÈë¿ÚÈ纣ÊÐò×Â¥Ò»°ã²»¿É×½Ãþ£¬ÓÐÈË˵ÕâÊÇΪÁ˸øÊÀÈËÔì³ÉÒ»ÖÖÉñÃظУ¬Ò²ÓÐÈË˵£¬ÕâÊÇΪÁ˶ã±ÜÉñÊÞºÓзµÄ׷ɱ¡£ÓÐÐÒ£¬ÎÒÕÒµ½ÁËÕâ¸öÈë¿Ú¡£µ«ÊDz»ÐÒµÄÊÇ£¬TMD×¢²áÕ˺Ż¹ÒªÑûÇëÂë¡£
»¹ºÃ£¬Õâ¸öÊÀ ......
Ç°ÑÔ:
¡¡¡¡ÔÚÎÒÃÇѧϰJavaµÄ¹ý³ÌÖÐ,ÕÆÎÕÆäÖеĻù±¾¸ÅÄî¶ÔÎÒÃǵÄѧϰÎÞÂÛÊÇJ2SE,J2EE,J2ME¶¼ÊǺÜÖØÒªµÄ,J2SEÊÇJavaµÄ»ù´¡,ËùÒÔÓбØÒª¶ÔÆäÖеĻù±¾¸ÅÄî×öÒÔ¹éÄÉ,ÒÔ±ã´ó¼ÒÔÚÒÔºóµÄѧϰ¹ý³ÌÖиüºÃµÄÀí½âjavaµÄ¾«Ëè,ÔÚ´ËÎÒ×ܽáÁË30Ìõ»ù±¾µÄ¸ÅÄî¡£
¡¡¡¡Java¸ÅÊö:
¡¡¡¡Ä¿Ç°JavaÖ÷ÒªÓ¦ÓÃÓÚÖмä¼þµÄ¿ª·¢(middleware)---´¦Àí¿Í» ......