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