回答问题接分
问题在源码中已经标出,问题出在LoginDAOImple.java中,
LoginDAOImple.java
package com.mfl.DataConn;
import java.util.*;
import java.sql.*;
import java.sql.ResultSet;
import com.mlf.Bean.LoginBean;
import java.sql.PreparedStatement;
import javax.servlet.ServletRequest;
public class LoginDAOImple implements LoginDAO
{
public ResultSet execute(String sql) throws Exception
{
return null;
// TODO 自动生成方法存根
}
public void insertInfo(LoginBean login) throws Exception
{
System.out.println("LoginDAOImple");
DataConnection dc=new DataConnection();
String sql="insert into userInfo(username,truename,pwd,pwd1,city,address,cardno,tel,email) values(?,?,?,?,?,?,?,?,?)";
try {
System.out.println("用户名:"+login.username);
System.out.println("真名:"+login.truename);
System.out.println("用户名:"+login.pwd);
System.out.println("用户名:"+login.pwd1);
System.out.println("用户名:"+login.city);
System.out.println("用户名:"+login.cardno);
System.out.println("用户名:"+login.tel);
System.out.println("用户名:"+login.email);
// 以上的用户名能够输出
System.out.println(dc.getConnection());//这里输出 为null
//dc对象中包含了class.forname,和getConnection,getConnectio中返回con
PreparedStatement pstmt=dc.getConnection().prepareStatement(sql);//问题可能出在这
System.out.println("sql执行");//这里没有执行
pstmt.setString(1,login.username);
pstmt.setString(2,login.truename);
pstmt.setString(3,login.pwd);
pstmt.setString(4,login.pwd1);
pstmt.setString(5,login.city);
pstmt.setString(6,login.address);
pstmt.setString(7,login.cardno);
pstmt.setString(8,login.tel);
pstmt.setString(9,login.email);
System.out.println("已经set");// 这也没有执行,
pstmt.execute();
}
catch (Exception ex) {
System.out.print(ex);
}
System.out.println("执行execute");//执行了,
/*
String sql="select * from userInfo";
System.out.println("sql=");
Statement stmt=con.createStatement();
System.out.println("执行execute");
stmt.executeQuery(sql);
*/
}
}
DataConnection.java这里应该错误,最好也看看
package com.mfl.DataConn;
import java.sql.*;
public class DataConnection
{ public String driver="sun.jdbc.odbc.JdbcOdbcDriver";
public String url="jdbc:odbc:shopping";
public String sqlName="sa";
public String sqlPasswrod="meng1986";
private Connection con=null;
public void DataConnection() throws
ClassNotFoundException,
SQLException {
try {
Class.forName(driver);
con=DriverManager.getConnection(url,sqlName,sqlPasswrod);
}
catch (Exception ex) {
}
}
public Connection getConnection()
{
return con;
}
public void close() throws SQLException
{
con.close();
}
}
------解决方案--------------------楼主啊.你的public void DataConnection() throws Class
NotFoundException, SQLException 根本就不是
你的构造方法啊..也就是说.你new一个DataConnection对象后直接调用它的getConnection()方法返回的connection
根本就没有得到初始化.也就是说是返回的它的默认值。 你指定的默认值是NU