package ga;
import java.sql.*;
public class Main {
public static void main(String[] args) throws ClassNotFoundException, SQLException {
//连接数据库
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://127.0.0.1:3306//test";
String username = "root";
String password = "000";
Connection conn = DriverManager.getConnection(url,username,password);
String id = "cxk";
String title = "1";
String description = "dawfaw";
String time = "2012-01-01";
String gtime ="0000000000";
String sql = "insert into ac (id, title, description, time, gtime) values (?, ?, ?, ?, ?)";
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setString(1, id);
pstmt.setString(2, title);
pstmt.setString(3, description);
pstmt.setString(4, time);
pstmt.setString(5, gtime);
int count = pstmt.executeUpdate(); //受影响的函数
System.out.println(count > 0); //判断是否成功插入
//释放资源
pstmt.close();
conn.close();
}
}
运行代码后表还是空的,哪里有问题?