JDBC driver is required to connect to the database. Add external jar in eclipse.
Package dB. test; import Java. SQL. *; public class jdbctest {public static void main (string [] ARGs) {// todo auto-generated method stub string driver = "com. mySQL. JDBC. driver "; string url =" JDBC: mysql: // 127.0.0.1: 3306/test "; string user =" dbtest "; string passwd =" 123456 "; try {class. forname (driver); connection conn = drivermanager. getconnection (URL, user, passwd); If (! Conn. isclosed () system. out. println ("success"); Statement statement = Conn. createstatement (); string SQL = "select * From dbstu"; resultset rs = statement.exe cutequery (SQL); system. out. println ("ID" + "\ t" + "name"); string name = NULL; while (RS. next () {name = Rs. getstring ("name"); system. out. println (RS. getstring ("ID") + "\ t" + name);} Rs. close (); statement. close (); Conn. close ();} catch (classno Tfoundexception e) {system. Out. println ("can not find the driver! "); E. printstacktrace ();} catch (sqlexception e) {e. printstacktrace ();} catch (exception e) {e. printstacktrace ();}}}