仓酷云
标题:
发布一篇java程序将汉字存进mysql数据库中时酿成乱码
[打印本页]
作者:
飘灵儿
时间:
2015-1-18 11:00
标题:
发布一篇java程序将汉字存进mysql数据库中时酿成乱码
有了这样一个呼声:让java代替C语言成为基本语言。这些足以说明java简单易学的这个优点。其次,java的功能强大,前面我也提到了,EJB3.0的推出使java成为了大型项目的首选。
明天忧郁了一天,java程序在向mysql拔出数据前不是乱码,数据库安装时也选了编码为utf8(和我程序的编码格局分歧)。但是拔出数据就酿成乱码,相称忧郁。
缘故原由:mysql的设置文件中的编码并没有改成utf8,;
办理举措:在mysql的安装目次下找到my.ini文件,将内里两处触及编码的中央改成utf8,以下:
#MySQLServerInstanceConfigurationFile
#----------------------------------------------------------------------
#GeneratedbytheMySQLServerInstanceConfigurationWizard
#
#
#InstallationInstructions
#----------------------------------------------------------------------
#
#OnLinuxyoucancopythisfileto/etc/my.cnftosetglobaloptions,
#mysql-data-dir/my.cnftosetserver-specificoptions
#(forthisinstallation)orto
#~/.my.cnftosetuser-specificoptions.
#
#OnWindowsyoushouldkeepthisfileintheinstallationdirectory
#ofyourserver(e.g.C:ProgramFilesMySQLMySQLServerX.Y).To
#makesuretheserverreadstheconfigfileusethestartupoption
#"--defaults-file".
#
#Torunruntheserverfromthecommandline,executethisina
#commandlineshell,e.g.
#mysqld--defaults-file="C:ProgramFilesMySQLMySQLServerX.Ymy.ini"
#
#ToinstalltheserverasaWindowsservicemanually,executethisina
#commandlineshell,e.g.
#mysqld--installMySQLXY--defaults-file="C:ProgramFilesMySQLMySQLServerX.Ymy.ini"
#
#Andthenexecutethisinacommandlineshelltostarttheserver,e.g.
#netstartMySQLXY
#
#
#Guildlinesforeditingthisfile
#----------------------------------------------------------------------
#
#Inthisfile,youcanusealllongoptionsthattheprogramsupports.
#Ifyouwanttoknowtheoptionsaprogramsupports,starttheprogram
#withthe"--help"option.
#
#Moredetailedinformationabouttheindividualoptionscanalsobe
#foundinthemanual.
#
#
#CLIENTSECTION
#----------------------------------------------------------------------
#
#ThefollowingoptionswillbereadbyMySQLclientapplications.
#NotethatonlyclientapplicationsshippedbyMySQLareguaranteed
#toreadthissection.IfyouwantyourownMySQLclientprogramto
#honorthesevalues,youneedtospecifyitasanoptionduringthe
#MySQLclientlibraryinitialization.
#
[client]
port=3306
[mysql]
<spanstyle="color:#ff0000;">default-character-set=utf8
</span>
#SERVERSECTION
#----------------------------------------------------------------------
#
#ThefollowingoptionswillbereadbytheMySQLServer.Makesurethat
#检察本栏目更多出色内容:http://www.bianceng.cn/Programming/Java/
#youhaveinstalledtheservercorrectly(seeabove)soitreadsthis
#file.
#
[mysqld]
#TheTCP/IPPorttheMySQLServerwilllistenon
port=3306
#Pathtoinstallationdirectory.Allpathsareusuallyresolvedrelativetothis.
basedir="C:/ProgramFiles/MySQL/MySQLServer5.5/"
#Pathtothedatabaseroot
datadir="C:/DocumentsandSettings/AllUsers/ApplicationData/MySQL/MySQLServer5.5/Data/"
#Thedefaultcharactersetthatwillbeusedwhenanewschemaortableis
#createdandnocharactersetisdefined
<spanstyle="color:#ff0000;">character-set-server=utf8
</span>#Thedefaultstorageenginethatwillbeusedwhencreatenewtableswhen
default-storage-engine=INNODB
#SettheSQLmodetostrict
sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
#ThemaximumamountofconcurrentsessionstheMySQLserverwill
#allow.Oneoftheseconnectionswillbereservedforauserwith
#SUPERprivilegestoallowtheadministratortologinevenifthe
#connectionlimithasbeenreached.
max_connections=100
#QuerycacheisusedtocacheSELECTresultsandlaterreturnthem
#withoutactualexecutingthesamequeryonceagain.Havingthequery
#cacheenabledmayresultinsignificantspeedimprovements,ifyour
#havealotofidenticalqueriesandrarelychangingtables.Seethe
#"Qcache_lowmem_prunes"statusvariabletocheckifthecurrentvalue
#ishighenoughforyourload.
#Note:Incaseyourtableschangeveryoftenorifyourqueriesare
#textuallydifferenteverytime,thequerycachemayresultina
#slowdowninsteadofaperformanceimprovement.
query_cache_size=0
#Thenumberofopentablesforallthreads.Increasingthisvalue
#increasesthenumberoffiledescriptorsthatmysqldrequires.
#Thereforeyouhavetomakesuretosettheamountofopenfiles
#allowedtoatleast4096inthevariable"open-files-limit"in
#section[mysqld_safe]
table_cache=256
#Maximumsizeforinternal(in-memory)temporarytables.Ifatable
#growslargerthanthisvalue,itisautomaticallyconvertedtodisk
#basedtableThislimitationisforasingletable.Therecanbemany
#ofthem.
tmp_table_size=17M
#Howmanythreadsweshouldkeepinacacheforreuse.Whenaclient
#disconnects,theclientsthreadsareputinthecacheiftherearent
#morethanthread_cache_sizethreadsfrombefore.Thisgreatlyreduces
#theamountofthreadcreationsneededifyouhavealotofnew
#connections.(Normallythisdoesntgiveanotableperformance
#improvementifyouhaveagoodthreadimplementation.)
thread_cache_size=8
#***MyISAMSpecificoptions
#ThemaximumsizeofthetemporaryfileMySQLisallowedtousewhile
#recreatingtheindex(duringREPAIR,ALTERTABLEorLOADDATAINFILE.
#Ifthefile-sizewouldbebiggerthanthis,theindexwillbecreated
#throughthekeycache(whichisslower).
myisam_max_sort_file_size=100G
#Ifthetemporaryfileusedforfastindexcreationwouldbebigger
#thanusingthekeycachebytheamountspecifiedhere,thenpreferthe
#keycachemethod.Thisismainlyusedtoforcelongcharacterkeysin
#largetablestousetheslowerkeycachemethodtocreatetheindex.
myisam_sort_buffer_size=34M
#SizeoftheKeyBuffer,usedtocacheindexblocksforMyISAMtables.
#Donotsetitlargerthan30%ofyouravailablememory,assomememory
#isalsorequiredbytheOStocacherows.Evenifyourenotusing
#MyISAMtables,youshouldstillsetitto8-64Masitwillalsobe
#usedforinternaltemporarydisktables.
key_buffer_size=25M
#SizeofthebufferusedfordoingfulltablescansofMyISAMtables.
#Allocatedperthread,ifafullscanisneeded.
read_buffer_size=64K
read_rnd_buffer_size=256K
#ThisbufferisallocatedwhenMySQLneedstorebuildtheindexin
#REPAIR,OPTIMZE,ALTERtablestatementsaswellasinLOADDATAINFILE
#intoanemptytable.Itisallocatedperthreadsobecarefulwith
#largesettings.
sort_buffer_size=256K
#***INNODBSpecificoptions***
#UsethisoptionifyouhaveaMySQLserverwithInnoDBsupportenabled
#butyoudonotplantouseit.Thiswillsavememoryanddiskspace
#andspeedupsomethings.
#skip-innodb
#AdditionalmemorypoolthatisusedbyInnoDBtostoremetadata
#information.IfInnoDBrequiresmorememoryforthispurposeitwill
#starttoallocateitfromtheOS.Asthisisfastenoughonmost
#recentoperatingsystems,younormallydonotneedtochangethis
#value.SHOWINNODBSTATUSwilldisplaythecurrentamountused.
innodb_additional_mem_pool_size=2M
#Ifsetto1,InnoDBwillflush(fsync)thetransactionlogstothe
#diskateachcommit,whichoffersfullACIDbehavior.Ifyouare
#willingtocompromisethissafety,andyouarerunningsmall
#transactions,youmaysetthisto0or2toreducediskI/Otothe
#logs.Value0meansthatthelogisonlywrittentothelogfileand
#thelogfileflushedtodiskapproximatelyoncepersecond.Value2
#meansthelogiswrittentothelogfileateachcommit,butthelog
#fileisonlyflushedtodiskapproximatelyoncepersecond.
innodb_flush_log_at_trx_commit=1
#ThesizeofthebufferInnoDBusesforbufferinglogdata.Assoonas
#itisfull,InnoDBwillhavetoflushittodisk.Asitisflushed
#oncepersecondanyway,itdoesnotmakesensetohaveitverylarge
#(evenwithlongtransactions).
innodb_log_buffer_size=1M
#InnoDB,unlikeMyISAM,usesabufferpooltocachebothindexesand
#rowdata.ThebiggeryousetthisthelessdiskI/Oisneededto
#accessdataintables.Onadedicateddatabaseserveryoumaysetthis
#parameterupto80%ofthemachinephysicalmemorysize.Donotsetit
#toolarge,though,becausecompetitionofthephysicalmemorymay
#causepagingintheoperatingsystem.Notethaton32bitsystemsyou
#mightbelimitedto2-3.5Gofuserlevelmemoryperprocess,sodonot
#setittoohigh.
innodb_buffer_pool_size=47M
#Sizeofeachlogfileinaloggroup.Youshouldsetthecombinedsize
#oflogfilestoabout25%-100%ofyourbufferpoolsizetoavoid
#unneededbufferpoolflushactivityonlogfileoverwrite.However,
#notethatalargerlogfilesizewillincreasethetimeneededforthe
#recoveryprocess.
innodb_log_file_size=24M
#NumberofthreadsallowedinsidetheInnoDBkernel.Theoptimalvalue
#dependshighlyontheapplication,hardwareaswellastheOS
#schedulerproperties.Atoohighvaluemayleadtothreadthrashing.
innodb_thread_concurrency=8
复制代码
首先第一点:jsp,servlet,javabean这些最基本的,嘿嘿,就算你是高手的话,在大行的企业级应用的话还是需要框架的,一个好的框架确实能构解决许多问题。
作者:
老尸
时间:
2015-1-20 12:31
接着就是EJB了,EJB就是Enterprise JavaBean, 看名字好象它是Javabean,可是它和Javabean还是有区别的。它是一个体系结构,你可以搭建更安全、更稳定的企业应用。它的大量代码已由中间件(也就是我们常听到的 Weblogic,Websphere这些J2EE服务器)完成了,所以我们要做的程序代码量很少,大部分工作都在设计和配置中间件上。
作者:
仓酷云
时间:
2015-1-21 11:12
Sun公司看见Oak在互联网上应用的前景,于是改造了Oak,于1995年5月以Java的名称正式发布。Java伴随着互联网的迅猛发展而发展,逐渐成为重要的网络编程语言。
作者:
小魔女
时间:
2015-1-30 16:44
设计模式是高级程序员真正掌握面向对象核心思想的必修课。设计模式并不是一种具体"技术",它讲述的是思想,它不仅仅展示了接口或抽象类在实际案例中的灵活应用和智慧
作者:
再见西城
时间:
2015-1-31 08:10
[url]http://www.jdon.com/[/url]去下载,或到同济技术论坛的服务器[url]ftp://nro.shtdu.edu.cn[/url]去下,安装上有什么问题,可以到论坛上去提问。
作者:
只想知道
时间:
2015-1-31 12:34
如果要向java web方向发展也要吧看看《Java web从入门到精通》学完再到《Struts2.0入门到精通》这样你差不多就把代码给学完了。有兴趣可以看一些设计模块和框架的包等等。
作者:
兰色精灵
时间:
2015-2-1 08:25
Java自面世后就非常流行,发展迅速,对C++语言形成了有力冲击。Java 技术具有卓越的通用性、高效性、平台移植性和安全性,广泛应用于个人PC、数据中心、游戏控制台
作者:
简单生活
时间:
2015-2-7 01:49
是一种语言,用以产生「小应用程序(Applet(s))
作者:
莫相离
时间:
2015-2-19 13:53
一直感觉JAVA很大,很杂,找不到学习方向,前两天在网上找到了这篇文章,感觉不错,给没有方向的我指了一个方向,先不管对不对,做下来再说。
作者:
爱飞
时间:
2015-3-6 14:55
我大二,Java也只学了一年,觉得还是看thinking in java好,有能力的话看英文原版(中文版翻的不怎么好),还能提高英文文档阅读能力。
作者:
柔情似水
时间:
2015-3-13 02:09
科学超级计算机、移动电话和互联网,同时拥有全球最大的开发者专业社群。
作者:
再现理想
时间:
2015-3-20 09:58
你可以去承接一些项目做了,一开始可能有些困难,可是你有技术积累,又考虑周全,接下项目来可以迅速作完,相信大家以后都会来找你的,所以Money就哗啦啦的。。。。。。
欢迎光临 仓酷云 (http://ckuyun.com/)
Powered by Discuz! X3.2