Java Mysql Connectivity Code
import java.sql.DriverManager;
import java.sql.ResultSet;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;
import com.mysql.jdbc.Statement;
public class jdbcConn {
private static Connection connect = null;
private static Statement statement = null;
private PreparedStatement preparedStatement = null;
private static ResultSet resultSet = null;
public static void main(String[] args) throws Exception
{ try {
// This will load the MySQL driver, each DB has its own driver
Class.forName("com.mysql.jdbc.Driver");
// Setup the connection with the DB
connect = (Connection) DriverManager.getConnection("jdbc:mysql://localhost/emp?"+"user=root");
statement = (Statement) connect.createStatement();
// Result set get the result of the SQL query
resultSet = statement.executeQuery("select * from emp");
// writeResultSet(resultSet);
while (resultSet.next()) {
String user = resultSet.getString("name");
System.out.println(user);
}
} catch (Exception e) {
System.out.println("error");
throw e;
}
}
}
import java.sql.ResultSet;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;
import com.mysql.jdbc.Statement;
public class jdbcConn {
private static Connection connect = null;
private static Statement statement = null;
private PreparedStatement preparedStatement = null;
private static ResultSet resultSet = null;
public static void main(String[] args) throws Exception
{ try {
// This will load the MySQL driver, each DB has its own driver
Class.forName("com.mysql.jdbc.Driver");
// Setup the connection with the DB
connect = (Connection) DriverManager.getConnection("jdbc:mysql://localhost/emp?"+"user=root");
statement = (Statement) connect.createStatement();
// Result set get the result of the SQL query
resultSet = statement.executeQuery("select * from emp");
// writeResultSet(resultSet);
while (resultSet.next()) {
String user = resultSet.getString("name");
System.out.println(user);
}
} catch (Exception e) {
System.out.println("error");
throw e;
}
}
}