以mysql为例子给一个代码示例:如下
public class MemberDAO {
public static final String DBDRIVER = "com.mysql.jdbc.Driver";
public static final String DBURL = "jdbc:mysql://localhost:3306/mldn";
public static final String DBUSER = "root";
public static final String DBPASS = "1234";
private PreparedStatement ps = null;
private Connection conn = null;
public MemberDAO() {
// DatabaseConnection dbc = new DatabaseConnection();
// this.conn = dbc.getConnection(conn);
}
//---------------------------------------插入信息----------------------------------
public boolean doInsert(Member member) throws Exception {
boolean flag = false;
String sql = "insert into member values(?,?,?,?,?,?,?,?,?)";
Connection conn = null;
Class.forName(DBDRIVER);
conn = DriverManager.getConnection(DBURL, DBUSER, DBPASS);
ps = conn.prepareStatement(sql);
ps.setString(1, member.getUserid());
ps.setString(2, member.getPassword());
ps.setString(3, member.getName());
ps.setString(4, member.getSex());
ps.setString(5, member.getPhone());
ps.setString(6, member.getEmail());
ps.setString(7, member.getInterest1());
ps.setString(8, member.getInterest2());
ps.setString(9, member.getNote());
if (ps.executeUpdate() > 0) {
flag = true;
}
conn.close();
ps.close();
return flag;
}
}
sql="insert into test (ID,title,describe,autor,matter) values ("+ID+",'"+title+"','"+describe+"','"+autor+"','"+matter+"')";
值不对吧
不是数据库的问题,就是语句的问题。建表语句有没有