Studyon Minte9.com
Jdbc




Mysql



Netbeans / Run / Set Project Configuration / Customize
Libraries / Add Library / Mysql JDBC Driver

package testexample; import java.sql.*; public class Test { // JDBC driver & Databse credentials static final String JDBC_DRIVER = "com.mysql.jdbc.Driver"; static final String URL = "jdbc:mysql://srvbvb01t/test"; static final String USER = "root"; static final String PASS = ""; public static void main(String args[]) { try { // Registrer (initialize) driver Class.forName("com.mysql.jdbc.Driver"); // Connection Connection conn = DriverManager.getConnection(URL,USER,PASS); Statement stmt = conn.createStatement(); // Query String sql = "SELECT * FROM employee"; ResultSet result = stmt.executeQuery(sql); while(result.next()) { int id = result.getInt("id"); String fname = result.getString("first_name"); String lname = result.getString("last_name"); int salary = result.getInt("salary"); System.out.println(fname + " " + lname + ": " + salary); // ion popescu: 100 } } catch (Exception e) { e.printStackTrace(); } } }