The project uses hibernate to connect to the database. More flexible database connections may be required when performing some special tasks. Record it for future use
Public static void main (string [] ARGs) {// driver name string driver = "com. mySQL. JDBC. driver "; // URL pointing to the name of the database to be accessed scutcsstring url =" JDBC: mysql: // ip: Port/database? Useunicode = true & characterencoding = utf8 "; // string user =" XXX "in MySQL configuration; // string Password =" XXX "in connection with MySQL configuration in Java "; try {// load the driver class. forname (driver); // continuous database connection conn = drivermanager. getconnection (URL, user, password); If (! Conn. isclosed () system. Out. println ("succeeded connecting to the database! "); // Statement is used to execute the SQL statement = Conn. createstatement (); // The SQL statement to be executed string SQL = "select * from XXX Where"; resultset rs = statement.exe cutequery (SQL); hashmap <integer, string> Hm = new hashmap <integer, string> (); int Index = 0; while (RS. next () {string filename = Rs. getstring ("FILENAME"); // system. out. println (filename); HM. put (index, filename); index ++;} Rs. close (); Conn. close (); system. out. PRI Ntln ("-----------------"); system. out. println ("database has" + HM. size () + "data");} catch (classnotfoundexception e) {system. out. println ("Sorry, can't find the driver! "); E. printstacktrace ();} catch (sqlexception e) {e. printstacktrace ();} catch (exception e) {e. printstacktrace ();}}