import java.sql.*;
public class hello {
public static void main(String[] args) {
String url="jdbc:mysql://localhost:3306/new";
String u="root";
String p="sa";
try{
Class.forName("com.mysql.jdbc.Driver");
Connection Con = DriverManager.getConnection(url,u,p);
Statement Stmt = Con.createStatement();
ResultSet RS=null;
RS= Stmt.executeQuery("SELECT * FROM table2");
while (RS.next()) {
String tt = RS.getString("ID");
System.out.print(tt);
tt = RS.getString("password");
System.out.print(tt);
}
RS.close();
}catch(SQLException e)
{
e.printStackTrace();
}catch(ClassNotFoundException e)
{
e.printStackTrace();
}
}
}
注:若在JSP里则增加