– first you need to get the jdbc driver and put it in your lib folder or in any place your build path.

– second use the next code:

Class.forName(“com.mysql.jdbc.Driver”).newInstance();

String url = “jdbc:mysql://hostname:3306/dbname”;

Connection con = DriverManager.getConnection(url,username,password);

Statement st = con.createStatement();

ResultSet rs = st.executeQuery(“your query here”);

while(rs.next())

{

System.out.println(rs.getString(“fieldname”));

}

con.close();

Advertisements