JAVA Connection MySQL database operation

Source: Internet
Author: User

String Strcon = "JDBC:MYSQL://122.114.147.148:3306/DDD";//Connection StringString struser = "Database user name";//String strpwd = "password";//"SYSTEM.OUT.PRINTLN ("Connecting Database ..."); Try{//Monitoring ExceptionsClass.forName ("Com.mysql.jdbc.Driver");//Load DriverConnection con; //Get the Connection objectCon =drivermanager.getconnection (Strcon, struser, strpwd); System.out.println ("Successfully connected to the database. "); Statement STA= Con.createstatement ();//To Create a statement object//Execute SQL statementString strSQL= "Select A.", A. Train type, A. driving time, B. Arrival time, a. Station, B. Station, CONCAT (Truncate ((b. Run time-A. Run time)/60,0), ' Hours ', mod ((b. Run time), 60) , ' minutes ') as run time, B. Hard seat-A. Hard seat +5 as hard seat from (SELECT * from sjc2222 where station like '% ' +textfield_3.gettext () + "% ') A, (SELECT * Fro M sjc2222 where station like '% ' +textfield_4.gettext () + "% ') b where a. n° = B. Train and A. Station Order < B. Station order by a. Driving time ASC"; ResultSet RS=sta.executequery (strSQL);  while(Rs.next ()) {Vector v=NewVector (); V.add (Rs.getstring ("A. Train")); V.add (Rs.getstring ("A. Train type")); V.add (Rs.getstring ("A. Driving time")); V.add (Rs.getstring ("B. Arrival Time")); V.add (Rs.getstring ("A. Station")); V.add (Rs.getstring ("B. Station")); V.add (Rs.getstring ("Run Time")); V.add (Rs.getstring (Hard seat));                      Dtm1.addrow (v);                    System.out.println (v);                    } System.out.println (Table_1.getrowcount ()); if(Table_1.getrowcount () = = 1) {table_1.setvisible (false); }Else{table_1.setvisible (true); } rs.close (); Sta.close ();                  Con.close (); } Catch(ClassNotFoundException cnfe) {cnfe.printstacktrace ();} Catch(SQLException Sqle) {Sqle.printstacktrace ();}

JAVA Connection MySQL database operation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.