代码:
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
public class Client {
//public static final String URL = "jdbc:mysql://localhost:172.0.0.1:mytest";
public static final String URL = "jdbc:mysql://localhost:3306/mytest";
public static final String USER = "root";
public static final String PASSWORD = "asdf";
public static void main(String[] args) throws ClassNotFoundException, SQLException {
Class.forName("com.mysql.jdbc.Driver");
Connection conn = null;
Statement st = null;
ResultSet rs = null;
try {
conn = DriverManager.getConnection(URL,USER,PASSWORD);
st = conn.createStatement();
//String sql = "insert into student(name,age,birthday,address) values('戴吉浩',17,'1998-01-00 05:30:30','贵州贵阳')";
st.execute(sql); //这种方法不适合本机子使用
int s = st.executeUpdate(sql);
System.out.println(s);
} catch (SQLException e) {
e.printStackTrace();
}finally{
if(st != null){
st.close();
}
if(conn != null){
conn.close();
}
}
}
}
问题是:st.execute(sql); 执行出错
st.executeUpdate(sql);执行可以
为什么啊 ?我下了好多的驱动都是这样,求大神帮忙啊 谢了
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
public class Client {
//public static final String URL = "jdbc:mysql://localhost:172.0.0.1:mytest";
public static final String URL = "jdbc:mysql://localhost:3306/mytest";
public static final String USER = "root";
public static final String PASSWORD = "asdf";
public static void main(String[] args) throws ClassNotFoundException, SQLException {
Class.forName("com.mysql.jdbc.Driver");
Connection conn = null;
Statement st = null;
ResultSet rs = null;
try {
conn = DriverManager.getConnection(URL,USER,PASSWORD);
st = conn.createStatement();
//String sql = "insert into student(name,age,birthday,address) values('戴吉浩',17,'1998-01-00 05:30:30','贵州贵阳')";
st.execute(sql); //这种方法不适合本机子使用
int s = st.executeUpdate(sql);
System.out.println(s);
} catch (SQLException e) {
e.printStackTrace();
}finally{
if(st != null){
st.close();
}
if(conn != null){
conn.close();
}
}
}
}
问题是:st.execute(sql); 执行出错
st.executeUpdate(sql);执行可以
为什么啊 ?我下了好多的驱动都是这样,求大神帮忙啊 谢了