import javax.xml.transform.Result;
import java.sql.*;
public class firstjdbc {
public static void main(String[] args) throws ClassNotFoundException, SQLException {
Class.forName("com.mysql.cj.jdbc.Driver");
String url ="jdbc:mysql://localhost:3306/school";
String username="root";
String pasword="123456";
Connection connection = DriverManager.getConnection(url, username, pasword);
// Statement statement = connection.createStatement();
#sql语句
String sql = "INSERT INTO student VALUES(?,?,?)";
#预编译
PreparedStatement st =connection.prepareStatement(sql);
#输入参数
st.setInt(1,7);
st.setObject(2,"wangwu");
st.setInt(3,10);
#正式编译
st.executeUpdate();
#断开连接
st.close();
connection.close();
}
}
09-20
07-30
248
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交