<%@ page import="java.sql.*"%>
<html>
<body>
<%
   String url = "jdbc:mysql://localhost/javaicq?user=&password=&useUnicode=true&characterEncoding=8859_1";   try{
   System.out.println("1111111111111111111111111111111111");
   Class.forName("org.gjt.mm.mysql.Driver").newInstance();
   System.out.println("2222222222222222222222222222222222");
   Connection conn= DriverManager.getConnection(url); 
   System.out.println("3333333333333333333333333333333333");
   Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
   System.out.println("4444444444444444444444444444444444");
   String sql="select * from icq"; 
   ResultSet rs=stmt.executeQuery(sql);
   System.out.println("5555555555555555555555555555555555");
   while(rs.next()) {%> 
First content:<%=rs.getString(5)%> 
Second content:<%=rs.getString(9)%> 
<%}%> 
<%System.out.print("Successfully!!!!");%> 
<%rs.close(); 
stmt.close(); 
conn.close(); 
   }catch(Exception ex){}
%></body> 
</html>
在用mysql我好像没有设置什么端口。
修改user pwd 是在mysql命令模式下的修改命令。可以试一试!

解决方案 »

  1.   

    public class LoadDriver { 
        public static void main(String[] args) { 
            try { 
                // The newInstance() call is a work around for some 
                // broken Java implementations            Class.forName("com.mysql.jdbc.Driver").newInstance(); 
            } catch (Exception ex) { 
                // handle the error 
            }
    }
    before you run the program you must open of run the mysql sever first
    see the http://dev.mysql.com/doc/connector/j/en for more details
      

  2.   

    import  java.sql.*;  
    public  class  ConnectMySql{  
               public  static  void  main(String  args[]){  
                           String  driver="org.gjt.mm.mqsql.Driver";  
                           String  url="jdbc:mysql://leo:3306/jxgl";  
                           String  user="leo";  
                           String  password="";  
                            Connection  con=null;
                           try{  
                                       Class.forName(driver);  
                           }  
                           catch(Exception  e){  
                                 System.out.println("Driver cannot be loaded!");  
                           }  
                           try{  
                                 con=DriverManager.getConnection(url,user,password);  
                                       if(con!=null)
                                                   System.out.println("数据连接成功");   
                           }  
                           catch(SQLException  ee){  
                                       System.out.println("数据连接失败");  
                           }  
               }                  if(con!=null){
                           con.close();
                    }
    }  
      

  3.   

    String  url="jdbc:mysql://leo:3306/jxgl";  
    错了阿~~~!!!
    url="jdbc:mysql://localhost://3306/database_name";
    String user="yourname"; String password="";
    Connection  con=DriverManager.getConnection(url,user,password);
    或者:
    url="jdbc:mysql://localhost://3306/database_name?user=Leo?password=";
    Connection con=DriverManager.getConnection(url);
    都可以的
      

  4.   

    if(con!=null){
                           con.close();
                    }
    应该提上一个括号里去