Skip to main content

Posts

Showing posts with the label MYSQL JDBC Connection in Java

MYSQL JDBC Connection in Java

Sample code to demonstrate MYSQL JDBC connectivity in Java Download mysql-connector-java-5.0.7.jar and add to your build path to run the code. Setup the project as show in the image below. package com.test; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.sql.Statement; import com.mysql.jdbc.ResultSet; public class TestConnection { public static void main(String[] argv) { System.out.println("******** MySQL JDBC Connection ********"); ResultSet rs = null; try { Class.forName("com.mysql.jdbc.Driver"); System.out.println("MySQL JDBC Driver Loaded"); Connection connection = null; connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root", "root"); Statement stmt = connection.createStatement(); rs= (ResultSet) stmt.executeQuery("select * from student"); while (rs.next()) { System.out.println...