Sample JDBC Connection Example JAVA,JDBC,MYSQL

/**
 * 
 */
package DatabaseConnection;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;


/**
 * @author satyanarayanagokavarapu
 *
 */
public class MySqlConnectionExample {

 /**
  * @param args
  */
 public static void main(String[] args) {
  // TODO Auto-generated method stub
  // creates three different Connection objects
  Connection conn2 = null;

  try {

   String url2 = "jdbc:mysql://localhost:3306/soccer?
   user=root&password=mysql123";
   conn2 = DriverManager.getConnection(url2);
   if (conn2 != null) {
    System.out.println("Connected to the database soccer");
   }
  } catch (SQLException ex) {
   System.out.println("An error occurred. Maybe user/password is
 invalid");
   ex.printStackTrace();
  }
 }

}

No comments:

Post a Comment

Featured Post

H1B Visa Stamping at US Consulate

  H1B Visa Stamping at US Consulate If you are outside of the US, you need to apply for US Visa at a US Consulate or a US Embassy and get H1...