public class Base { /**
 * @param args
 */
public static void main(String[] args) {
    static void template() throws Exception {
     String url="jdbc:mysql://localhost:3306/jsbc";
     String user="root";
     String password="admin";
     Connection conn=null;
     Statement st=null;
     ResultSet rSet=null;
     try{
     Class.forName("com.mysql.jdbc.Driver");
     conn=DriverManager.getConnection(url,user,password);
     st=conn.createStatement();
     rSet=st.executeQuery("select * from user");
     while(rSet.next()){
     System.out.println(rSet.getObject(1)+"\t"+rSet.getObject(2)
                    +"\t"+rSet.getObject(3)+"\t");
     }
     }finally{
     try{
     if(rSet!=null)
     rSet.close();
     }finally{
     try{
     if(st!=null)
     st.close();
     }finally{
     if(conn!=null)
     conn.close();
     }
     }
     }
}
}
请问这段代码哪里出问题啦,我拿myeclipse7.0运行老是出错,提示‘{’有问题,不懂。

解决方案 »

  1.   

    少了
    public class Base { 
    这一层的大括号
      

  2.   


    public class Base{  /** 
    * @param args 
    */ static void template() throws Exception { 
        String url="jdbc:mysql://localhost:3306/jsbc"; 
        String user="root"; 
        String password="admin"; 
        Connection conn=null; 
        Statement st=null; 
        ResultSet rSet=null; 
        try{ 
        Class.forName("com.mysql.jdbc.Driver"); 
        conn=DriverManager.getConnection(url,user,password); 
        st=conn.createStatement(); 
        rSet=st.executeQuery("select * from user"); 
        while(rSet.next()){ 
         System.out.println(rSet.getObject(1)+"\t"+rSet.getObject(2) 
                      +"\t"+rSet.getObject(3)+"\t"); 
         }
        }
        finally{ 
         try{ 
         if(rSet!=null) 
         rSet.close(); 
         }finally{ 
         try{ 
         if(st!=null) 
         st.close(); 
         }finally{ 
         if(conn!=null) 
         conn.close(); 
         } 
         } 
         } 

    public static void main(String[] args) throws Exception{ 
    template();
    }
    }
      

  3.   

    能告诉我你在main方法里还定义了个方法是怎么想的吗?把这个改掉之后,在在最后加个大括号就行了