Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- /**
- *
- * @author alaa
- */
- // import com.sun.org.apache.bcel.internal.util.ClassPath;
- import java.sql.*;
- public class MysqlConnect
- {
- public static void main (String[] args)
- {
- Connection conn = null;
- try
- {
- //String username = "root";
- //String password = "password";
- //String database = "quiz";
- String url = "jdbc:mysql://127.0.0.1/quiz?user=root&password=password";
- Class.forName ("com.mysql.jdbc.Driver").newInstance ();
- conn = DriverManager.getConnection (url);
- System.out.println ("Database connection established");
- }
- catch (Exception e)
- {
- // System.out.println(System.getenv("CLASSPATH"));
- System.err.println ("Cannot connect to database server");
- }
- finally
- {
- if (conn != null)
- {
- try
- {
- conn.close ();
- System.out.println(System.getenv("CLASSPATH"));
- System.out.println ("Database connection terminated");
- }
- catch (Exception e) { /* ignore close errors */ }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment