You have to download driver from dev.mysql.com
And attach jar file to the project.
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class JDBCProject
{
public static void main(String[] args)
{
Connection con=null;
try
{
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/ts","root","root");
if(con!=null)
System.out.println("Connection Successfully Established...");
}
catch (ClassNotFoundException e)
{
e.printStackTrace();
}
catch (SQLException e)
{
e.printStackTrace();
}
finally
{
try
{
con.close();
} catch (SQLException e)
{
e.printStackTrace();
}
}
}
}
No comments:
Post a Comment