Guest User

Untitled

a guest
Mar 3rd, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.97 KB | None | 0 0
  1. import java.sql.Connection;
  2. import java.sql.DriverManager;
  3. import java.sql.SQLException;
  4.  
  5. public class JDBCTest {
  6.     public static void main(String[] args) {
  7.         String url = null ;
  8.         String driver = null ;
  9.         Connection conn = null ;
  10.         String db = null ;
  11.         try
  12.         {
  13.             url = "jdbc:mysql://VPREMOTELOGGER:3306/";
  14.             db = "logger";
  15.             driver = "com.mysql.jdbc.Driver";
  16.             Class.forName(driver);
  17.             conn = DriverManager.getConnection(url+db, "remoteUsr", "changme");
  18.             System.out.println("Reached end without exception");
  19.         }
  20.         catch(ClassNotFoundException classNotFound)
  21.         {
  22.             System.out.println("Class Not Found");
  23.             classNotFound.printStackTrace();
  24.         }
  25.         catch(SQLException sql)
  26.         {
  27.             System.out.println("SQL Exception");
  28.             sql.printStackTrace();
  29.         }
  30.         finally
  31.         {
  32.             if (conn != null)
  33.                 try {
  34.                     conn.close();
  35.                 } catch (SQLException e) {
  36.                     System.out.println("Connection not closed properly");
  37.                     e.printStackTrace();
  38.                 }
  39.         }
  40.     }
  41.  
  42. }
Add Comment
Please, Sign In to add comment