展开全部
public static void insert(int id, String name, String age){
String sql = "insert into 表名(id, name, age) value (?,?,?);";
try {
Class.forName("驱动");
Connection conn = DriverManager.getConnection("地址","数据库名","数据库密码");
PreparedStatement psm = conn.prepareStatement(sql);
psm.setInt(1,id);
psm.setString(2, name);
psm.setString(3, age);
int i = psm.executeUpdate();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
String sql = "insert into 表名(id, name, age) value (?,?,?);";
try {
Class.forName("驱动");
Connection conn = DriverManager.getConnection("地址","数据库名","数据库密码");
PreparedStatement psm = conn.prepareStatement(sql);
psm.setInt(1,id);
psm.setString(2, name);
psm.setString(3, age);
int i = psm.executeUpdate();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询