import java.sql.*;
public class mysql
{
public static void main(String[] args)
{
try
{
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/test";
String userName = "root";
String passwd = "root";
Connection con = DriverManager.getConnection(url, userName, passwd);
Statement st = con.createStatement();
String query = "select * from user;";
ResultSet rs = st.executeQuery(query);
while(rs.next())
{
int num = rs.getInt("id");
String name = rs.getString("username");
System.out.println(num+" "+name);
}
rs.close();
st.close();
con.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}