回 帖 发 新 帖 刷新版面

主题:求助

package appClass;

import DbMng.ConectionMng;
import java.sql.*;
import java.util.*;

/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: </p>
* @author unascribed
* @version 1.0
*/

public class Person {

  public void addperson(String sql) {
    Connection con = ConectionMng.getConection();
    try {
      Statement stmt = con.createStatement();
      stmt.executeUpdate(sql);
      con.close();
    }
    catch (Exception ex) {
      System.out.println("addperson error  "+ex.getMessage());
    }

  }

  public void updateperson(String sql) {
    Connection con = ConectionMng.getConection();
    try {
      Statement stmt = con.createStatement();
      stmt.executeUpdate(sql);
      con.close();
    }
    catch (Exception ex) {
      System.out.println("updateperson error  "+ex.getMessage());
    }
  }

  public void deleteperson(String sql) {
    Connection con = ConectionMng.getConection();
    try {
      Statement stmt = con.createStatement();
      stmt.executeUpdate(sql);
      con.close();
    }
    catch (Exception ex) {
      System.out.println("deleteperson error  "+ex.getMessage());
    }
  }

  public ResultSet personQuery(String condition) {
    ResultSet rs =null;
    //Map map = new HashMap();
    String sql = "";
    if (condition != null)
      sql += sql + condition;
    else
      sql = "select * from person";

    Connection con = ConectionMng.getConection();
    try {
      Statement stmt = con.createStatement();
      rs= stmt.executeQuery(sql);
      //con.close();
     // map.put("rs",rs);
      //map.put("con",con);
      return rs;

    }
    catch (Exception ex) {
      System.out.println("执行查询失败!" + ex.getMessage());
      return null;
    }
  }
}
编译后程序提示以下异常,那位大哥能给我指出我错在那拉!谢谢拉!
--------------------Configuration: j2sdk1.4.2_03 <Default>--------------------
F:\appClass\Person.java:3: package DbMng does not exist
import DbMng.ConectionMng;
             ^
F:\appClass\Person.java:19: cannot resolve symbol
symbol  : variable ConectionMng
location: class appClass.Person
    Connection con = ConectionMng.getConection();
                     ^
F:\appClass\Person.java:32: cannot resolve symbol
symbol  : variable ConectionMng
location: class appClass.Person
    Connection con = ConectionMng.getConection();
                     ^
F:\appClass\Person.java:44: cannot resolve symbol
symbol  : variable ConectionMng
location: class appClass.Person
    Connection con = ConectionMng.getConection();
                     ^
F:\appClass\Person.java:64: cannot resolve symbol
symbol  : variable ConectionMng
location: class appClass.Person
    Connection con = ConectionMng.getConection();
                     ^
5 errors

Process completed.

回复列表 (共2个回复)

沙发

DbMng.ConectionMng是什么啊,你在哪找的?

板凳

我写的一个类代码如下
ConectionMng是package DbMng;
import java.util.*;
import java.sql.*;

/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: </p>
* @author unascribed
* @version 1.0
*/

public class ConectionMng {

  public ConectionMng() {
  }

  public static Connection getConection() {
    try {
      Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
      Connection conn = DriverManager.getConnection("jdbc:microsoft:sqlserver://192.168.1.8:1433;DatabaseName=odata", "sa", "");
      return conn;
    }
    catch (Exception ex) {
      System.out.println("获得数据库连接异常!  " + ex.getMessage());
      return null;
    }
  }

  public static void main(String[] args) {
    if (getConection() != null)
      System.out.println("数据库连接成功 !");
  }
}

我来回复

您尚未登录,请登录后再回复。点此登录或注册