补充上面的代码:
各位大侠帮帮忙呀!小弟在此谢过了。我为这个问题搞了一天多了;望大侠给于帮助package com.ToDataBase;
import java.sql.*;//连接数据的类
public class ConnectionClientInfo
{
public static Connection getConnection()
{
Connection conn = null;
String FormName = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
String DB = "jdbc:microsoft.sqlserver://localhost:1433;DatabaseName=eew_ClientInfo";
String USER = "testid";
String PWD = "testpwd";
try
{
Class.forName(FormName).newInstance(); 
conn = DriverManager.getConnection(DB,USER,PWD);
}
catch(Exception e)
{
 e.printStackTrace();
}
return conn;
}

public static String getName()
{
String name = "测试二的信息";
return name;
}
}

解决方案 »

  1.   

    错误提示:unreported exception java.sql.SQLEXception;must be caugt or declared to be thrown
           Statement stmt = conn.createStatement();//这里出错;
      

  2.   

    getConnection()方法后面捕获异常,throw sqlexception
      

  3.   

    public static Connection getConnection() Throw SQLException()
      

  4.   

    加一个异常处理就行了,如下!
    public static String getNewBusiness()
    {      
                      try{
    Statement stmt=conn.createStatement(); //编译这里出错
    ResultSet homeRst = stmt.executeQuery("select WebName,StorePath from B_webStore");
                   }catch(SQLException e){
                    e.printStackTrace();
     }
    }
      

  5.   

    处理是这样嘛?
    catch(Exception e)
    {
    e.printStackTrace();
    throw e;
    }
      

  6.   

    加一个异常处理就行了,如下!
    public static String getNewBusiness()
    {      
                      try{
    Statement stmt=conn.createStatement(); //编译这里出错
    ResultSet homeRst = stmt.executeQuery("select WebName,StorePath from B_webStore");
                   }catch(SQLException e){
                    e.printStackTrace();
     }
    }提示:
    syhomerevalue.java:22:non-static variable conn cannot be referenced from a staic context                 Statement stmt = conn.createStatement()  //这里出错
      

  7.   

    public static String getNewBusiness()
    你在该静态方法中不能引用非静态字段conn
      

  8.   

    还是基础啊!基础问题,
    方法一:将conn声明为private static Connection conn
    方法二:将getNewBusiness这个方法前面的static去掉,这样用这个方法时要用这个类的实例!
      

  9.   

    那个用public static Connection getNewBusiness()如何?
    而且也不行
      

  10.   

    我这个代码是要用JSP里的。。小弟对JAVA没有怎么学过。。还望各位帮帮忙
      

  11.   

    这是我现在的代码,不知编写正确否?不过还是出错提示:
    syhomerevalue.java:22:non-static variable conn cannot be referenced from a staic context                 Statement stmt = conn.createStatement()  //这里出错
    那位大侠能不能帮我合理的把这个代码整理一下?
    package com.ModePage;
    import com.ToDataBase.*;
    import java.io.*;
    import java.sql.*;
    import java.util.*;
    //系统首面对象转换值public class SyHomeReValue
    { //公共对象,获得数据库的连接
    private Connection conn;
    public SyHomeReValue(){
    this.conn = ConnectionClientInfo.getConnection();
    }
    public static Connection getConnection()
    {
    try{
    Statement stmt=conn.createStatement(); //编译这里出错
    ResultSet homeRst = stmt.executeQuery("select WebName,StorePath from B_webStore");
                      }catch(SQLException e){
                      e.printStackTrace();
                      }

    }

    }
      

  12.   

    有两种改法:
    第一种如下:
    package com.ModePage;
    import com.ToDataBase.*;
    import java.io.*;
    import java.sql.*;
    import java.util.*;
    //系统首面对象转换值public class SyHomeReValue
    { //公共对象,获得数据库的连接
    private static Connection conn;
    public SyHomeReValue(){
    this.conn = ConnectionClientInfo.getConnection();
    }
    public static Connection getConnection()
    {
    try{
    Statement stmt=conn.createStatement(); //编译这里出错
    ResultSet homeRst = stmt.executeQuery("select WebName,StorePath from B_webStore");
                      }catch(SQLException e){
                      e.printStackTrace();
                      }

    }

    }-------------------
    第二种:
    package com.ModePage;
    import com.ToDataBase.*;
    import java.io.*;
    import java.sql.*;
    import java.util.*;
    //系统首面对象转换值public class SyHomeReValue
    { //公共对象,获得数据库的连接
    private Connection conn;
    public SyHomeReValue(){
    this.conn = ConnectionClientInfo.getConnection();
    }
    public Connection getConnection()
    {
    try{
    Statement stmt=conn.createStatement(); //编译这里出错
    ResultSet homeRst = stmt.executeQuery("select WebName,StorePath from B_webStore");
                      }catch(SQLException e){
                      e.printStackTrace();
                      }

    }

    }
    第二种在调用时要这样调用:SyHomeReValue sr=new SyHomeReValue(); sr.getConnection();
    这些都是基础,你自己看看基本的语法规则吧!
      

  13.   

    好。。谢谢各位的帮助!
    zhutouzip兄能给我介绍几本学习书籍吗?
      

  14.   

    看Thinking in java,我认为最好的!