mysql导入问题? 数据库有个表Config:这个表第一个字段为自动增加式...现在客户那我也不知道已经有多少条数据了...下面这段语句该如何写才能真确插入,插入后第一个字段根据序列自动填充(表已经设置该字段为自动填充)!INSERT INTO `Config` VALUES (?, '3', '','0');我用?表示 出错! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 比如:数据表已经有5条数据 或者 6条数据 现在运行这段SQL后 的第一个字段为 6 或 7 可以自动填充!现在问题是这段SQL第一个字段值该如何表示? INSERT INTO <表名> [(<字段名1> [,<字段名2>, ...])] VALUES (<常量1> [,<常量2>, ...]) 在insert 中写出明确的字段名 INSERT INTO <表名> [(<字段名1> [,<字段名2>, ...])] VALUES (<常量1> [,<常量2>, ...])如果字段是自动增长型你就可以把它在<表名>后省略就可以了 try { // Load the database driver Class.forName("org.gjt.mm.mysql.Driver"); // Get a Connection to the database connection = DriverManager.getConnection(connectionURL, "root", "admin"); //Add the data into the database String sql = "insert into emp_details values (?,?,?,?,?,?,?,?)"; PreparedStatement pst = connection.prepareStatement(sql); pst.setString(1, uId); pst.setString(2, fname); pst.setString(3, sname); pst.setString(4, address1); pst.setString(5, address2); pst.setString(6, town); pst.setString(7, county); pst.setString(8, zipcode); int numRowsChanged = pst.executeUpdate(); // show that the new account has been created out.println(" Hello : "); out.println(" '"+fname+"'"); pst.close(); } catch(ClassNotFoundException e){ out.println("Couldn't load database driver: " + e.getMessage()); } catch(SQLException e){ out.println("SQLException caught: " + e.getMessage()); } catch (Exception e){ out.println(e); } finally { // Always close the database connection. try { if (connection != null) connection.close(); } catch (SQLException ignored){ out.println(ignored); } } } 这个问题很简单,有两种方法,第一个就是你问号那个位置设为0,在mysql中,如果你的字段已经设置为自增长,那么添0,它就会设为该字段最大值+1,第二种方法好像你已经知道了 设为自增了,就可以了,写个null,都没问题,它应该会自己判断的 KindEditor图片上传问题 急招网站开发程序员(J2EE) jsp从数据库读取图片问题! 关于用JSP写工行在线支付的程序 JSP菜鸟一问 救救小妹:SQL SERVER 2000中的JPEG图片在Jsp上显示乱码问题,急盼回复! 请教在JSP中读取XML文档中“ 中文数据 “的问题???? Java 运行问题 java.lang.NoSuchMethodError: org.jdom.Element.getChildren()Ljava/util/List; 关于PreparedStatement报错 用myeclise做web开发如何配置三层开发结构 求解答
数据表已经有5条数据 或者 6条数据 现在运行这段SQL后 的第一个字段为 6 或 7 可以自动填充!现在问题是这段SQL第一个字段值该如何表示?
// Load the database driver
Class.forName("org.gjt.mm.mysql.Driver");
// Get a Connection to the database
connection = DriverManager.getConnection(connectionURL, "root", "admin");
//Add the data into the database
String sql = "insert into emp_details values (?,?,?,?,?,?,?,?)";
PreparedStatement pst = connection.prepareStatement(sql);
pst.setString(1, uId);
pst.setString(2, fname);
pst.setString(3, sname);
pst.setString(4, address1);
pst.setString(5, address2);
pst.setString(6, town);
pst.setString(7, county);
pst.setString(8, zipcode);
int numRowsChanged = pst.executeUpdate();
// show that the new account has been created
out.println(" Hello : ");
out.println(" '"+fname+"'");
pst.close();
}
catch(ClassNotFoundException e){
out.println("Couldn't load database driver: " + e.getMessage());
}
catch(SQLException e){
out.println("SQLException caught: " + e.getMessage());
}
catch (Exception e){
out.println(e);
}
finally {
// Always close the database connection.
try {
if (connection != null) connection.close();
}
catch (SQLException ignored){
out.println(ignored);
}
}
}