JDBC and MySQL
Thursday, August 25th, 2011
import java.util.logging.Level;
import java.util.logging.Logger;
// import com.mysql.jdbc.*;
import java.sql.*;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author sukanta
*/
public class Main {
public static void main(String[] args) throws SQLException {
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
con = DriverManager.getConnection("jdbc:mysql://datanase name", "username", "password");
stmt = con.createStatement();
ResultSet result = stmt.executeQuery("SELECT * FROM table1");
while (result.next())
System.out.println(result.getString(1) + " " + result.getString(2));
result.close();
con.close();
}
}
