Guest User

Untitled

a guest
Jul 9th, 2018
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.81 KB | None | 0 0
  1. //java -classpath "~/JConnector/mysql-connector-java-5.1.18;." SQLTest password
  2. import java.sql.*;
  3.  
  4. public class SQLTest{
  5.     public static void main(String[] args){
  6.        
  7.         Connection myCon = null;
  8.        
  9.         try{
  10.            
  11.             Class.forName("com.mysql.jdbc.Driver").newInstance();
  12.             myCon = DriverManager.getConnection("jdbc:mysql:///test", "root", args[0]); //args[0] being password
  13.             if(!myCon.isClosed())
  14.                 System.out.println("SUCCESS");
  15.        
  16.         }catch(Exception e){
  17.             System.out.println(e);
  18.        
  19.         }finally{
  20.            
  21.             try{
  22.                
  23.                 if(myCon != null)
  24.                     myCon.close();
  25.            
  26.             }catch(SQLException er){
  27.             }
  28.         }
  29.     }
  30. }
Add Comment
Please, Sign In to add comment