´«ÖDz¥¿Íjavaѧϰ jdbc³õ²½
ÎÒ½ñÌìѧϰÁËÓÃjdbcÁ¬½ÓÊý¾Ý¿âµÄ֪ʶ£¬ÎÒ×öÁ˼òµ¥µÄ±Ê¼Ç£º
1.Êý¾Ý¿âµÄurl jdbc:mysql://loaclhost:3306/test
jdbc:±íʾÁ¬½ÓÊý¾Ý¿âʹÓõÄÊÇjdbcÐÒé
mysql£º±íʾÁ¬½ÓÊý¾Ý¿âµÄ×ÓÐÒ飬²»Í¬µÄÊý¾Ý¿âʹÓõÄÐÒé²» Ò»Ñù
localhost£ºÊý¾Ý¿â·þÎñÆ÷ËùÔÚµÄipµØÖ·
3306 £ºÊ¹ÓõĶ˿ںÅ
test£ºÁ¬½ÓµÄÊý¾Ý¿â
2.Class.forname("com.mysql.jdbc.Driver")
Ëü¼ÓÔØÁË×Ö½ÚÂ룬µ«²»µ÷ÓÃcom.mysql.jdbc.DriverÀàµÄ¹¹Ôì·½ ·¨£¬
Ëü×¢²áÁËÇý¶¯£¬µ÷ÓõÄÊÇcom.mysql.jdbc.DriverµÄ¾²Ì¬´úÂë ¿é
3.Á¬½ÓÊý¾Ý¿âÓÐÒ쳣ʱ£¬ÓÃtry-catch´¦Àí
4.´´½¨statement¶ÔÏ󣬿ÉÒÔ¿´³ÉÒ»¸öÈÝÆ÷£¬ÓÃÀ´ÔËËÍsqlÓï¾ä£¬
stmt=conn.createStatemrnt();
5.×éÖ¯sqlÓï¾ä£¬
String sql="insert into test(id,name)
values(null,'ccc')"; null´ú±í×ÔÔö
Ö´ÐÐsqlÓï¾ä£ºint k=symt.executeUpdate(sql);
executeUpdate ¿ÉÒÔÖ´Ðиø¶¨µÄsqlÓï¾ä£¬
Ö´ÐÐDML£¨insert update delete£©·µ»ØÖµÊÇÓ°ÏìµÄÐÐÊý£¬
Ö´ÐÐDDL£¨create alter drop£©Óï¾ä ·µ»ØÖµÊÇ0
6.¹Ø±ÕÁ¬½Ó£ºÏȹØstatement£¬ÔÚ¹Øconn£¬
if stmt!=null stmt.close();
if conn!=null conn.close();
7.Ö´ÐÐÊý¾Ý¿âµÄ²éѯÓï¾ä£»
***************·½·¨Ò»:
String sql="select id ,name from test";
Resultset rs= stmt.executeQuery(sql);//·µ»ØֵΪResultset
Resultset ÊÇÒ»¸ö½á¹û¼¯£¬¸ú±íµÄ½á¹¹ÀàËÆ£¬
8.´ÓResultset ÀïÃæÈ¡Êý¾Ýʱ£¬¹â±ê´¦ÓÚµÚÒ»ÐÐÊý¾ÝµÄÇ°Ã棬
rs.next();//½«½á¹û¼¯µÄ¹â±êÏÂÒÆÒ»ÐУ¬
rs.getXxxxx(columneLable) ²ÎÊýÊÇÁеÄË÷ÒýÖµ,¸ÃË÷ÒýÖµ´Ó1 ¿ªÊ¼ 2 3...
int id=rs.getInt(1);//È¡µÚÒ»ÁÐÊý¾Ý,
String name=rs.getString(2);//È¡µÚ¶þÁÐÊý¾Ý
9.ʹÓÃwhile±éÀú //²»ÓÃÅжÏrs£¡=null £¬ÒòΪrs ÓÀÔ¶²»Îª¿Õ
while(rs.next){
int id=rs.getInt(1);
String name=rs.getString(2);
system.out.print(id+" "+name);
}
10.¹Ø±ÕµÄ˳Ðò£ºrs stmt conn
***********·½·¨¶þ£º
rs.next();//½«½á¹û¼¯µÄ¹â±êÏÂÒÆÒ»ÐУ¬
Èç¹ûδָ¶¨ SQL AS ×Ӿ䣬Ôò±êÇ©ÊÇÁÐÃû³Æ
int id=rs.getInt("id");//È¡ÁÐΪ"id"Êý¾Ý
String name=rs.getString("name");//È¡ÁÐ
Ïà¹ØÎĵµ£º
public class select {
public List XiuGai_select(String keyword){
List list=new ArrayList();
Connection conn = null;
Statement stmt = null;
String sql=null;
ResultSet res = null;
get ......
¼°Ê±Ïû³ý²»Ê¹ÓõĶÔÏóµÄÒýÓÃ, ÀíÂÛÉÏ, ´øÓÐÄÚ´æ¹ÜÀíµÄÓïÑÔÊDz»´æÔÚÄÚ´æй©µÄ, µ«ÊÇÈç¹û¶Ô¶ÔÏóµÄ²Ù×÷²»µ±,Ò²ÊÇ¿ÉÄÜ»áÔì³ÉÄÚ´æй©. ÈçÓÐÒ»¸östack, Æäpopº¯ÊýÈçÏÂ. public Object pop() { if( Element.length() == 0) return nu ......
ÔÚÂÛ̳Àï¿´ÁËdaquan198163ËùдµÄ¡¶³õѧRORµÄÒÉ»ó¡·ÕâƪÎÄÕ£¬robbinÔڻظ´ÖиøÁËÏêϸµÄ½â´ð£¬¿ÉÊÇ¿´Íê½â´ðÖ®ºó£¬ÎÒÒ²²úÉúÁËһЩÒÉ»ó£¬ÔÚ´ËÏëÎÊÎÊ¡£
ÔÚrobbinËù¸ø³öµÄ½â´ðµ±ÖУ¬¸ü¶àµÄÊDzûÊörailsµÄºÃ´¦£¬È»¶ø´ó¼Ò¶¼ÖªµÀ£¬railsÖ»Ê ......
maven ÏàÐźܶàÈ˶¼Óõ½Ìý¹ý£¬ÓõÄÈËÓ¦¸Ã²»ÊǺܶ࣬ÖÁÉÙÎÒÃǹ«Ë¾1000È˼¶±ðµÄIT²¿ÃŶ¼Ã»Óá£
¸´Ôӳ̶Ⱦö¶¨¹¤¾ßµÄʹÓÃÇé¿ö£¬¸ÕÈëÃŵijÌÐòÔ±Èç¹ûûÓÐÒ»ÖÖÁ¼ºÃµÄѧϰÐÄ̬¿´Á˿϶¨»á¶ÔantÓе㱧Թ(ʹµÃÄã²»ÄܺܿìÔÚecÉÏ¿´µ½½á¹û)¡£¿öÇÒ²»Ëµmaven×öµÄºÃ²»ºÃ£¬ÆðÂëÄܸø´óÐÍÏîÄ¿µÄ¹ÜÀíÌṩһÖÖеÄ˼·¡£×Ô¶¯»¯ÄܼõÉٺܶàʱ¼äºÍ½» ......