Linux (Ubuntu platform)JavaConnect to the MySQL database through JDBC, which is similar to that on the Windows platform. The procedure is as follows:
DownloadJDBC: mysql-connector-java-5.1.18.tar.gz
ExtractJDBC: Tar-ZxvfMysql-connector-java-5.1.18.tar.gz
ConfigurationJDBC:CPMysql-connector-java-5.1.18-bin.jar/usr/local/jdk1.6.0 _ 22/JRE/lib/EXT/
Java example:
Private Static string SQL = "select top, ID, name, country, dtime from gametop800 where id = \" com. Rovio. angrybirds \"";
Public mysqlconnect () {<br/> string dbdriver = "com. mySQL. JDBC. driver "; <br/> string url =" JDBC: mysql: // localhost/top800 "; <br/> string username =" root "; <br/> string Password = ""; </P> <p> statement mstatement = NULL; <br/> resultset mresultset = NULL; <br/> connection mconnection = NULL; </P> <p> string SQL = "select top, ID, name, country, dtime from gametop800 where top <= 20 "; </P> <p> try {<br/> class. forna Me (dbdriver ). newinstance (); <br/> mconnection = drivermanager. getconnection (URL, username, password); <br/> mstatement = mconnection. createstatement (); <br/> mresultset = mstatement.exe cutequery (SQL); </P> <p> try {<br/> while (mresultset. next () {<br/> system. out. print (mresultset. getint (1) + "\ t"); <br/> system. out. print (mresultset. getstring (2) + "\ t"); <br/> system. out. print (mresultset. getstring (3) + "\ t "); <Br/> system. out. println (mresultset. getstring (4); <br/>}< br/>} catch (exception e) {<br/> system. out. println ("database read error! \ N "+ E. getmessage (); <br/>}< br/>} catch (sqlexception e) {<br/> system. out. println ("database connection error: \ n" + URL + "\ n" + E. getmessage (); <br/>}catch (exception e) {<br/> E. printstacktrace (); <br/>}finally {<br/> // mstatement. close (); <br/> // mconnection. close (); <br/>}< br/>}
Execution result:
Complete source code