程序地带

springboot中如何使用JDBC来实现对数据库的增删改查操作


简单使用
引入依赖

这里我们只引入基本的依赖就好,创建一个springboot项目(这里版本是2.1.6),然后添加以下依赖:


https://unsplash.com/collections/65033833https://unsplash.com/collections/89931451https://unsplash.com/collections/86572748https://unsplash.com/collections/23891973https://unsplash.com/collections/36714792https://unsplash.com/collections/84571638https://unsplash.com/collections/42505270https://unsplash.com/collections/21807062https://unsplash.com/collections/40091997https://unsplash.com/collections/55660318https://unsplash.com/collections/91073320https://unsplash.com/collections/66181831https://unsplash.com/collections/54244588https://unsplash.com/collections/20818407https://unsplash.com/collections/93544575https://unsplash.com/collections/46670682https://unsplash.com/collections/49850784https://unsplash.com/collections/52228423https://unsplash.com/collections/59407587https://unsplash.com/collections/33342445https://unsplash.com/collections/68152646https://unsplash.com/collections/55670978https://unsplash.com/collections/19302339https://unsplash.com/collections/72775014https://unsplash.com/collections/38328429https://unsplash.com/collections/79525907https://unsplash.com/collections/31890953https://unsplash.com/collections/37028666https://unsplash.com/collections/61390772https://unsplash.com/collections/22532042https://unsplash.com/collections/65105270https://unsplash.com/collections/13143975https://unsplash.com/collections/85249501https://unsplash.com/collections/37135305https://unsplash.com/collections/78888775https://unsplash.com/collections/15926676https://unsplash.com/collections/14809683https://unsplash.com/collections/72007278https://unsplash.com/collections/61484419https://unsplash.com/collections/57419486https://unsplash.com/collections/29852348https://unsplash.com/collections/41940539https://unsplash.com/collections/72815268https://unsplash.com/collections/25343604https://unsplash.com/collections/39914154https://unsplash.com/collections/86269352https://unsplash.com/collections/82479764https://unsplash.com/collections/94616024https://unsplash.com/collections/92906151https://unsplash.com/collections/89978255https://unsplash.com/collections/94543808https://unsplash.com/collections/79290838https://unsplash.com/collections/48504966https://unsplash.com/collections/42903523https://unsplash.com/collections/28292159https://unsplash.com/collections/98113064https://unsplash.com/collections/69444834https://unsplash.com/collections/75059663https://unsplash.com/collections/51992006https://unsplash.com/collections/13369084https://unsplash.com/collections/67891482https://unsplash.com/collections/61875439https://unsplash.com/collections/27233682https://unsplash.com/collections/47700809https://unsplash.com/collections/98205154https://unsplash.com/collections/69559007https://unsplash.com/collections/44499282https://unsplash.com/collections/19693065https://unsplash.com/collections/64697097https://unsplash.com/collections/46758933https://unsplash.com/collections/31275516https://unsplash.com/collections/21605695https://unsplash.com/collections/33092357https://unsplash.com/collections/34045468https://unsplash.com/collections/71812532https://unsplash.com/collections/50482794https://unsplash.com/collections/72394929https://unsplash.com/collections/94832256https://unsplash.com/collections/89361499https://unsplash.com/collections/43559528https://unsplash.com/collections/51242709https://unsplash.com/collections/47941916https://unsplash.com/collections/22892756https://unsplash.com/collections/74389830https://unsplash.com/collections/55200631https://unsplash.com/collections/84583760https://unsplash.com/collections/74788095https://unsplash.com/collections/24638524https://unsplash.com/collections/57924929https://unsplash.com/collections/42936878https://unsplash.com/collections/25257414https://unsplash.com/collections/27835604https://unsplash.com/collections/55543092https://unsplash.com/collections/90986194https://unsplash.com/collections/56595353https://unsplash.com/collections/49086146https://unsplash.com/collections/89150825https://unsplash.com/collections/28120854https://unsplash.com/collections/88664190https://unsplash.com/collections/62771969https://unsplash.com/collections/20643242https://unsplash.com/collections/97750770https://unsplash.com/collections/43856502https://unsplash.com/collections/47769586https://unsplash.com/collections/67094088https://unsplash.com/collections/82929948https://unsplash.com/collections/62262534https://unsplash.com/collections/13193019https://unsplash.com/collections/74215040https://unsplash.com/collections/46097481https://unsplash.com/collections/67145041https://unsplash.com/collections/30688710https://unsplash.com/collections/73089384https://unsplash.com/collections/82516853https://unsplash.com/collections/20558500https://unsplash.com/collections/32733674https://unsplash.com/collections/78855288https://unsplash.com/collections/93741170https://unsplash.com/collections/61269351https://unsplash.com/collections/65534146https://unsplash.com/collections/34250355https://unsplash.com/collections/28460536https://unsplash.com/collections/30645788https://unsplash.com/collections/88064669https://unsplash.com/collections/65729547https://unsplash.com/collections/73172374https://unsplash.com/collections/97101927https://unsplash.com/collections/26638389https://unsplash.com/collections/37376575https://unsplash.com/collections/76955658https://unsplash.com/collections/68093533https://unsplash.com/collections/52234647https://unsplash.com/collections/75772003https://unsplash.com/collections/23019966https://unsplash.com/collections/31304203https://unsplash.com/collections/71302292https://unsplash.com/collections/51703260https://unsplash.com/collections/63758724https://unsplash.com/collections/60998464https://unsplash.com/collections/31804895https://unsplash.com/collections/55129631https://unsplash.com/collections/69040299https://unsplash.com/collections/29502084https://unsplash.com/collections/95659535https://unsplash.com/collections/51616286https://unsplash.com/collections/57451334https://unsplash.com/collections/65724480https://unsplash.com/collections/81906664https://unsplash.com/collections/47814211https://unsplash.com/collections/64139637https://unsplash.com/collections/14788168https://unsplash.com/collections/74968421https://unsplash.com/collections/86131458https://unsplash.com/collections/85093295https://unsplash.com/collections/61727849https://unsplash.com/collections/76209227https://unsplash.com/collections/48898487https://unsplash.com/collections/82347886https://unsplash.com/collections/33928706https://unsplash.com/collections/87972469https://unsplash.com/collections/76954969https://unsplash.com/collections/17057721https://unsplash.com/collections/90699534https://unsplash.com/collections/21873675https://unsplash.com/collections/43146389https://unsplash.com/collections/19812979https://unsplash.com/collections/33419441https://unsplash.com/collections/57013668https://unsplash.com/collections/13290829https://unsplash.com/collections/32179559https://unsplash.com/collections/81469985https://unsplash.com/collections/59823483https://unsplash.com/collections/88861620https://unsplash.com/collections/51796205https://unsplash.com/collections/46976765https://unsplash.com/collections/42694664https://unsplash.com/collections/48284779https://unsplash.com/collections/54372294https://unsplash.com/collections/54613589https://unsplash.com/collections/82147417https://unsplash.com/collections/88429231https://unsplash.com/collections/54170803https://unsplash.com/collections/95487449https://unsplash.com/collections/19319604https://unsplash.com/collections/60834840https://unsplash.com/collections/78713635https://unsplash.com/collections/80871998https://unsplash.com/collections/15850451https://unsplash.com/collections/80341724https://unsplash.com/collections/44392430https://unsplash.com/collections/68231338https://unsplash.com/collections/97320984https://unsplash.com/collections/40083477https://unsplash.com/collections/99950107https://unsplash.com/collections/40634000https://unsplash.com/collections/82501674https://unsplash.com/collections/19744322https://unsplash.com/collections/38872704https://unsplash.com/collections/56130780https://unsplash.com/collections/93560302https://unsplash.com/collections/89062289https://unsplash.com/collections/65053873https://unsplash.com/collections/81815082https://unsplash.com/collections/29303606https://unsplash.com/collections/36277596https://unsplash.com/collections/99718788https://unsplash.com/collections/27929978https://unsplash.com/collections/36997418https://unsplash.com/collections/34617697https://unsplash.com/collections/69187347https://unsplash.com/collections/24122795https://unsplash.com/collections/47593905https://unsplash.com/collections/37235919https://unsplash.com/collections/67154554https://unsplash.com/collections/24205463https://unsplash.com/collections/31668824https://unsplash.com/collections/37919659https://unsplash.com/collections/14408895https://unsplash.com/collections/88039310https://unsplash.com/collections/94241966https://unsplash.com/collections/46966528https://unsplash.com/collections/77953177https://unsplash.com/collections/43421936https://unsplash.com/collections/87886617https://unsplash.com/collections/25570769https://unsplash.com/collections/87693230https://unsplash.com/collections/97039556https://unsplash.com/collections/68025306https://unsplash.com/collections/37413643https://unsplash.com/collections/28751377https://unsplash.com/collections/40480993https://unsplash.com/collections/81979947https://unsplash.com/collections/95811452https://unsplash.com/collections/66638053https://unsplash.com/collections/33330715https://unsplash.com/collections/67332301https://unsplash.com/collections/50091061https://unsplash.com/collections/73727154https://unsplash.com/collections/59391936https://unsplash.com/collections/45269686https://unsplash.com/collections/70076849https://unsplash.com/collections/38773165https://unsplash.com/collections/38764653https://unsplash.com/collections/51301762https://unsplash.com/collections/44375178https://unsplash.com/collections/53718134https://unsplash.com/collections/91742674https://unsplash.com/collections/47796556https://unsplash.com/collections/60715540https://unsplash.com/collections/70460982https://unsplash.com/collections/40268557https://unsplash.com/collections/31614340https://unsplash.com/collections/50474167https://unsplash.com/collections/21975754https://unsplash.com/collections/51066315https://unsplash.com/collections/81944456https://unsplash.com/collections/70159855https://unsplash.com/collections/96249288https://unsplash.com/collections/47014706https://unsplash.com/collections/74562707https://unsplash.com/collections/38161578https://unsplash.com/collections/42480460https://unsplash.com/collections/59997488https://unsplash.com/collections/89306452https://unsplash.com/collections/75388918https://unsplash.com/collections/72822798https://unsplash.com/collections/79270349https://unsplash.com/collections/63994115https://unsplash.com/collections/91585362https://unsplash.com/collections/59777203https://unsplash.com/collections/29872836https://unsplash.com/collections/48252777https://unsplash.com/collections/80469922https://unsplash.com/collections/60699869https://unsplash.com/collections/88113001https://unsplash.com/collections/87375113https://unsplash.com/collections/61997425https://unsplash.com/collections/69865284https://unsplash.com/collections/34143613https://unsplash.com/collections/55564098https://unsplash.com/collections/20380751https://unsplash.com/collections/57306954https://unsplash.com/collections/53394362https://unsplash.com/collections/49626393https://unsplash.com/collections/68640030https://unsplash.com/collections/96289287https://unsplash.com/collections/73303050https://unsplash.com/collections/53934503https://unsplash.com/collections/81216332https://unsplash.com/collections/13211247https://unsplash.com/collections/92667626https://unsplash.com/collections/60853217https://unsplash.com/collections/76552802https://unsplash.com/collections/40765804https://unsplash.com/collections/71787513https://unsplash.com/collections/52018195https://unsplash.com/collections/36955599https://unsplash.com/collections/38953468https://unsplash.com/collections/61135934https://unsplash.com/collections/39404542https://unsplash.com/collections/99013929https://unsplash.com/collections/17540126https://unsplash.com/collections/48964606https://unsplash.com/collections/75923988https://unsplash.com/collections/86758259https://unsplash.com/collections/34304066https://unsplash.com/collections/20104271https://unsplash.com/collections/99639423https://unsplash.com/collections/51003615https://unsplash.com/collections/35882101https://unsplash.com/collections/93653741https://unsplash.com/collections/93880889https://unsplash.com/collections/66233727https://unsplash.com/collections/18323871https://unsplash.com/collections/53411964https://unsplash.com/collections/44937756https://unsplash.com/collections/39085417https://unsplash.com/collections/30869243https://unsplash.com/collections/67799129https://unsplash.com/collections/65153283https://unsplash.com/collections/91200846https://unsplash.com/collections/22586622https://unsplash.com/collections/28759996https://unsplash.com/collections/53698863https://unsplash.com/collections/44860009https://unsplash.com/collections/68768164https://unsplash.com/collections/30740498https://unsplash.com/collections/95726183https://unsplash.com/collections/16378962https://unsplash.com/collections/93807670https://unsplash.com/collections/26469625https://unsplash.com/collections/15798468https://unsplash.com/collections/30085224https://unsplash.com/collections/87516136https://unsplash.com/collections/59288720https://unsplash.com/collections/22465936https://unsplash.com/collections/32164281https://unsplash.com/collections/37294906https://unsplash.com/collections/44109140https://unsplash.com/collections/76976873https://unsplash.com/collections/66002422https://unsplash.com/collections/76173950https://unsplash.com/collections/31415969https://unsplash.com/collections/46753659https://unsplash.com/collections/53025399https://unsplash.com/collections/34044676https://unsplash.com/collections/39962486https://unsplash.com/collections/33820792https://unsplash.com/collections/14900742https://unsplash.com/collections/71951043https://unsplash.com/collections/93540819https://unsplash.com/collections/35796777https://unsplash.com/collections/29633572https://unsplash.com/collections/26154429https://unsplash.com/collections/70161364https://unsplash.com/collections/23131157https://unsplash.com/collections/21372788https://unsplash.com/collections/71186284https://unsplash.com/collections/69596213https://unsplash.com/collections/87723863https://unsplash.com/collections/44850247https://unsplash.com/collections/38043048https://unsplash.com/collections/48887564https://unsplash.com/collections/69993253https://unsplash.com/collections/58243786https://unsplash.com/collections/47041898https://unsplash.com/collections/64309910https://unsplash.com/collections/16807321https://unsplash.com/collections/30485871https://unsplash.com/collections/55353672https://unsplash.com/collections/25965125https://unsplash.com/collections/24531238https://unsplash.com/collections/19407988https://unsplash.com/collections/52775468https://unsplash.com/collections/65007177https://unsplash.com/collections/86801133https://unsplash.com/collections/48878812https://unsplash.com/collections/87316557https://unsplash.com/collections/86872996https://unsplash.com/collections/32962239https://unsplash.com/collections/18014693https://unsplash.com/collections/26636301https://unsplash.com/collections/58019620https://unsplash.com/collections/40969272https://unsplash.com/collections/40060175https://unsplash.com/collections/45282537https://unsplash.com/collections/33007616https://unsplash.com/collections/50652458https://unsplash.com/collections/34695314https://unsplash.com/collections/80856636https://unsplash.com/collections/91526539https://unsplash.com/collections/31882578https://unsplash.com/collections/57826716https://unsplash.com/collections/57727653https://unsplash.com/collections/98085520https://unsplash.com/collections/61325204https://unsplash.com/collections/43029115https://unsplash.com/collections/73272497https://unsplash.com/collections/42451823https://unsplash.com/collections/39442246https://unsplash.com/collections/15649506https://unsplash.com/collections/82829364https://unsplash.com/collections/26140491https://unsplash.com/collections/56741087https://unsplash.com/collections/92925667https://unsplash.com/collections/49443649https://unsplash.com/collections/62438216https://unsplash.com/collections/59700943https://unsplash.com/collections/25014855https://unsplash.com/collections/50518082https://unsplash.com/collections/69025398https://unsplash.com/collections/26037990https://unsplash.com/collections/49336158https://unsplash.com/collections/15907536https://unsplash.com/collections/26555492https://unsplash.com/collections/14871438https://unsplash.com/collections/66521947https://unsplash.com/collections/69247056https://unsplash.com/collections/17302408https://unsplash.com/collections/32603173https://unsplash.com/collections/64054584https://unsplash.com/collections/23587474https://unsplash.com/collections/19887216https://unsplash.com/collections/65119698https://unsplash.com/collections/84590463https://unsplash.com/collections/69491127https://unsplash.com/collections/58495416https://unsplash.com/collections/88700171https://unsplash.com/collections/86180540https://unsplash.com/collections/23165855https://unsplash.com/collections/66739827https://unsplash.com/collections/14226005https://unsplash.com/collections/20505512https://unsplash.com/collections/47255887https://unsplash.com/collections/60391212https://unsplash.com/collections/32740261https://unsplash.com/collections/33488053https://unsplash.com/collections/63526139https://unsplash.com/collections/29561812https://unsplash.com/collections/13051353https://unsplash.com/collections/46016418https://unsplash.com/collections/73632864https://unsplash.com/collections/44207615https://unsplash.com/collections/32673535https://unsplash.com/collections/24083059https://unsplash.com/collections/52116501https://unsplash.com/collections/75667030https://unsplash.com/collections/87794902https://unsplash.com/collections/34709071https://unsplash.com/collections/23358019https://unsplash.com/collections/91950586https://unsplash.com/collections/44556467https://unsplash.com/collections/76879031https://unsplash.com/collections/22076476https://unsplash.com/collections/30540195https://unsplash.com/collections/30929491https://unsplash.com/collections/66250828https://unsplash.com/collections/27531342https://unsplash.com/collections/81084085https://unsplash.com/collections/18912340https://unsplash.com/collections/44254650https://unsplash.com/collections/36075602https://unsplash.com/collections/35099291https://unsplash.com/collections/46400089https://unsplash.com/collections/89487216https://unsplash.com/collections/49839960https://unsplash.com/collections/56593163https://unsplash.com/collections/74011843https://unsplash.com/collections/44461015https://unsplash.com/collections/74711085https://unsplash.com/collections/82139504https://unsplash.com/collections/71675086https://unsplash.com/collections/69242865https://unsplash.com/collections/82728697https://unsplash.com/collections/17074322https://unsplash.com/collections/78745037https://unsplash.com/collections/24045490https://unsplash.com/collections/32815736https://unsplash.com/collections/83386179https://unsplash.com/collections/59707987https://unsplash.com/collections/97802480https://unsplash.com/collections/95927573https://unsplash.com/collections/31199515https://unsplash.com/collections/26044089https://unsplash.com/collections/86397710https://unsplash.com/collections/27249072https://unsplash.com/collections/76844237https://unsplash.com/collections/98186641https://unsplash.com/collections/78473382https://unsplash.com/collections/46331654https://unsplash.com/collections/53122617https://unsplash.com/collections/64321612https://unsplash.com/collections/57131987https://unsplash.com/collections/42479442https://unsplash.com/collections/44309603https://unsplash.com/collections/96000566https://unsplash.com/collections/20105760https://unsplash.com/collections/27832820https://unsplash.com/collections/22693623https://unsplash.com/collections/56559607https://unsplash.com/collections/31520502https://unsplash.com/collections/47512491https://unsplash.com/collections/88730286https://unsplash.com/collections/79330458https://unsplash.com/collections/72129264https://unsplash.com/collections/89315730https://unsplash.com/collections/62789791https://unsplash.com/collections/58994052https://unsplash.com/collections/21986170https://unsplash.com/collections/31712770https://unsplash.com/collections/45649987https://unsplash.com/collections/25707724https://unsplash.com/collections/65601102https://unsplash.com/collections/98622266https://unsplash.com/collections/36715968https://unsplash.com/collections/24397265https://unsplash.com/collections/68146579https://unsplash.com/collections/57848908https://unsplash.com/collections/14079273https://unsplash.com/collections/65862073https://unsplash.com/collections/88551358https://unsplash.com/collections/32716035https://unsplash.com/collections/49763945https://unsplash.com/collections/31153728https://unsplash.com/collections/70288324https://unsplash.com/collections/73165386https://unsplash.com/collections/13602678https://unsplash.com/collections/84585602https://unsplash.com/collections/56085486https://unsplash.com/collections/95936405https://unsplash.com/collections/69139195https://unsplash.com/collections/73570638https://unsplash.com/collections/42104263https://unsplash.com/collections/59127597https://unsplash.com/collections/89962091https://unsplash.com/collections/94825125https://unsplash.com/collections/72258434https://unsplash.com/collections/21707622https://unsplash.com/collections/47868367https://unsplash.com/collections/65239494https://unsplash.com/collections/15926033https://unsplash.com/collections/44101171https://unsplash.com/collections/20429464https://unsplash.com/collections/71811999https://unsplash.com/collections/48249221https://unsplash.com/collections/76459764https://unsplash.com/collections/46601472https://unsplash.com/collections/19858926https://unsplash.com/collections/46488075https://unsplash.com/collections/27298039https://unsplash.com/collections/68107777https://unsplash.com/collections/53367246https://unsplash.com/collections/28418802https://unsplash.com/collections/76799350https://unsplash.com/collections/77101938https://unsplash.com/collections/94101343https://unsplash.com/collections/13494295https://unsplash.com/collections/86835118https://unsplash.com/collections/90399406https://unsplash.com/collections/90134993https://unsplash.com/collections/33085624https://unsplash.com/collections/82195165https://unsplash.com/collections/83282684https://unsplash.com/collections/33157641https://unsplash.com/collections/94741815https://unsplash.com/collections/19548029https://unsplash.com/collections/78337088https://unsplash.com/collections/30354718https://unsplash.com/collections/90423626https://unsplash.com/collections/38049687https://unsplash.com/collections/73574955https://unsplash.com/collections/33231964https://unsplash.com/collections/72356984https://unsplash.com/collections/31256935https://unsplash.com/collections/70171433https://unsplash.com/collections/63930010https://unsplash.com/collections/29005092https://unsplash.com/collections/88543771https://unsplash.com/collections/57026082https://unsplash.com/collections/79323903https://unsplash.com/collections/17411213https://unsplash.com/collections/17032338https://unsplash.com/collections/68748806https://unsplash.com/collections/52342559https://unsplash.com/collections/50903687https://unsplash.com/collections/99667924https://unsplash.com/collections/47739311https://unsplash.com/collections/70855935https://unsplash.com/collections/48155539https://unsplash.com/collections/94543747https://unsplash.com/collections/93268453https://unsplash.com/collections/40445934https://unsplash.com/collections/44648616https://unsplash.com/collections/81021185https://unsplash.com/collections/99790533https://unsplash.com/collections/26053963https://unsplash.com/collections/90422671https://unsplash.com/collections/28494115https://unsplash.com/collections/92098008https://unsplash.com/collections/45224189https://unsplash.com/collections/93542444https://unsplash.com/collections/48046272https://unsplash.com/collections/85566735https://unsplash.com/collections/68918438https://unsplash.com/collections/61030874https://unsplash.com/collections/66146239https://unsplash.com/collections/78398945https://unsplash.com/collections/15432256https://unsplash.com/collections/90706308https://unsplash.com/collections/33391053https://unsplash.com/collections/25233246https://unsplash.com/collections/36047099https://unsplash.com/collections/14946935https://unsplash.com/collections/20929092https://unsplash.com/collections/98461617https://unsplash.com/collections/85362553https://unsplash.com/collections/17943592https://unsplash.com/collections/14945132https://unsplash.com/collections/38846221https://unsplash.com/collections/91421852https://unsplash.com/collections/82845238https://unsplash.com/collections/29075761https://unsplash.com/collections/86066356https://unsplash.com/collections/19040647https://unsplash.com/collections/96864148https://unsplash.com/collections/94438360https://unsplash.com/collections/64319373https://unsplash.com/collections/76847560https://unsplash.com/collections/85741105https://unsplash.com/collections/79504115https://unsplash.com/collections/33527786https://unsplash.com/collections/33253216https://unsplash.com/collections/47691295https://unsplash.com/collections/94842508https://unsplash.com/collections/45468024https://unsplash.com/collections/45756196https://unsplash.com/collections/81321780https://unsplash.com/collections/41534358https://unsplash.com/collections/51599676https://unsplash.com/collections/54899624https://unsplash.com/collections/14110594https://unsplash.com/collections/81748377https://unsplash.com/collections/69851992https://unsplash.com/collections/23360450https://unsplash.com/collections/73708697https://unsplash.com/collections/76829370https://unsplash.com/collections/21943818https://unsplash.com/collections/54443358https://unsplash.com/collections/45363289https://unsplash.com/collections/31878592https://unsplash.com/collections/49786166https://unsplash.com/collections/68929177https://unsplash.com/collections/49294104https://unsplash.com/collections/74226966https://unsplash.com/collections/76857973https://unsplash.com/collections/81154498https://unsplash.com/collections/17371748https://unsplash.com/collections/85056456https://unsplash.com/collections/81211189https://unsplash.com/collections/68452203https://unsplash.com/collections/30493312https://unsplash.com/collections/46026581https://unsplash.com/collections/69259072https://unsplash.com/collections/93223757https://unsplash.com/collections/32267200https://unsplash.com/collections/98842630https://unsplash.com/collections/39557063https://unsplash.com/collections/33163061https://unsplash.com/collections/36798303https://unsplash.com/collections/22429888https://unsplash.com/collections/42347354https://unsplash.com/collections/75956356


<dependencies>
<!--jdbc-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<!--mysql驱动-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtimen</scope>
</dependency>
<!--web-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--test-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>
编写配置文件

这里我们需要把数据库的基本连接信息配置好


spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
## 这里如果不配置时区可能会报错,所以配置时区:serverTimezone=UT
url: jdbc:mysql://localhost:3306/study_springboot?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8
username: root
password: root
编写测试类
@RunWith(SpringRunner.class)
@SpringBootTest
public class BaseTest {
@Autowired
private DataSource dataSource;
@Test
public void load(){
// 打印出:class com.zaxxer.hikari.HikariDataSource
System.out.println(dataSource.getClass());
}
}
实现增删改查

spring boot中有很多的xxxTemplate,也就是给我们默认配置了 很多的模板,方便我们进行开发,比如上面测试中的 JdbcTemplate,spring boot已经给我们封装好方法了,我们只要调用就好,下面是增删改查的案例:


@RestController
public class TestController {
@Autowired
private JdbcTemplate jdbcTemplate;
@GetMapping("/userList")
public List<Map<String, Object>> getUserList(){
String sql = "select * from study_springboot.user";
List<Map<String, Object>> maps = jdbcTemplate.queryForList(sql);
return maps;
}
@GetMapping("/addUser")
public String addUser(){
String sql = "insert into study_springboot.user(id, name, password) values('1', 'zhangsan', 'qqqq')";
jdbcTemplate.update(sql);
return "add success";
}
/**
* 可以通过占位符实现入参
* @param id
* @return
*/
@GetMapping("/updateUser/{id}")
public String updateUser(@PathVariable("id") int id){
String sql = "update study_springboot.user set name =?, password = ? where id = "+id;
// 封装占位符
Object[] objects = new Object[2];
objects[0] = "李四";
objects[1] = "pppppp";
jdbcTemplate.update(sql, objects);
return "update success";
}
@GetMapping("/deleteUser/{id}")
public String deleteUser(@PathVariable("id") int id){
String sql = "delete from study_springboot.user where id = ?";
// int 类型也是一个object,所以这样传参也是可以的
jdbcTemplate.update(sql, id);
return "delete success";
}
}

上面的案例只是展示基本的操作,但是真实项目中是不会这样写的,一般还是整合MyBatis或者JPA来实现操作数据源。


版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_24219625/article/details/112761039

随机推荐

Python高级编程技巧实战学习_Day10

 学习资源传送门:Python高级编程技巧实战_哔哩哔哩(゜-゜)つロ干杯~-bilibili(一)学习内容:如何将多个小字符串拼接成一个大的字...

QFIUNE 阅读(220)

Linux学习总结(九)回收子进程

孤儿进程父进程先于子进程结束,则子进程成为孤儿进程,子进程的父进程称为init进程,称为init进程领养孤儿进程。#include<stdio.h>...

vegetablesssss 阅读(664)

随机单词答题游戏(JAVA gui实现)

案例描述:java-gui实现单词游戏,随机显示单词,键盘在文本框中输入想对应的单词,回答正确加5分,错误扣三分**##案例图片回...

啊道~ 阅读(227)