数据库openConnection错了,错误信息不是告诉你了吗?

解决方案 »

  1.   

    我感觉是读哪个属性文件出了问题,但是我把那一段单独抽出来又能运行,不知道为什么,openConnection出错好象是因为属性文件没有读取,所以数据库不能连接。
    下面是我抽出来的那段程序,编译后能运行。
    package db;import java.util.*;
    import java.sql.*;
    import java.io.*;public class test
    {public static void main(String args[])
    {
    Connection conn = null;
    Statement stmt = null;
        ResultSet rset = null; Properties prop = new Properties();
    try{
    String filename = "db/db.properties";
    FileInputStream is = new FileInputStream(filename);
    //InputStream is = getClass().getResourceAsStream("/db.properties");
    prop.load(is);
    if (is != null) is.close();
    }catch(IOException e){
        System.out.println("[DbConnection] 打开文件时出现错误");
        System.out.println(e);
    }    String jdbc = prop.getProperty("drivers");
        String url = prop.getProperty("url");
        String user = prop.getProperty("user");
        String password = prop.getProperty("password");    System.out.println("jdbc=[" + jdbc + "]");
        System.out.println("url=[" + url + "]");
        System.out.println("user=[" + user + "]");
        System.out.println("password=[" + password + "]");
        System.out.println(jdbc);
        System.out.println(url);
        System.out.println(user);
        System.out.println(password);
        try{
    Class.forName(jdbc);
    }catch(ClassNotFoundException e){
    System.out.println("JDBC 登录过程中出现错误" + e.getMessage()); } try{
    conn = DriverManager.getConnection(url,user,password);
    }catch(SQLException e){
    System.out.println("生成Connection过程中出现错误:" + e.getMessage());
    }
    }
    }
      

  2.   

    Some problem has happend on my input method, so I only can type Eglish here. I wish I can express exactly. I read your code carefully, but I found no problem in your beans. I only doubt the string you typed as follows:
    String query = "SELECT M_NAME,M_PASSWORD FROM FORUM_MEMBERS WHERE M_NAME="+request.getParameter("username")+" AND M_PASSWORD="+request.getParameter("password");I think it should looks like this:
    String query = "SELECT M_NAME,M_PASSWORD FROM FORUM_MEMBERS WHERE M_NAME='"+request.getParameter("username")+"' AND M_PASSWORD='"+request.getParameter("password") + "'", but i don't know where I am right because my DBMS is oracle, and yours is SQLServer.still others, the error infomation you supplied above tells me that the problem happened when your application try to read the propertiy file, so you should verify if your file is located in the exact location. I'm afraid I can not give you more suggestion.