final String MYSQLDBDRIVER="org.gjt.mm.mysql.Driver"; final String MYSQLDBURL="jdbc:mysql://localhost/test"; final String MYSQLDBUSER="root"; final String MYSQLDBUSERPASS="root"; Connection con = null; try{ Class.forName(MYSQLDBDRIVER); con = DriverManager.getConnection(MYSQLDBURL,MYSQLDBUSER,MYSQLDBUSERPASS); Statement stmt = con.createStatement(); String sql = "select * from student"; ResultSet rs = stmt.executeQuery(sql); while(rs.next()){ out.print(rs.getString(1) + " " + rs.getString(2)); } rs.close(); stmt.close(); con.close(); } catch(Exception e){ out.println(e); }