笔记如上
学了个代码
php;gutter:true;
import java.sql.*;</p>
<p>public class jdbc01 {
public static void main(String[] args) {
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
//注册驱动
DriverManager.registerDriver(new com.mysql.jdbc.Driver());
//获取连接
conn = DriverManager.getConnection("jdbc:mysql//localhost:3306/student", "root", "123456");
//执行SQL
String insertSql = "insert into dept(deptno,dname,loc) values(01,'第一','m',20)";
stmt.executeUpdate(insertSql);</p>
<pre><code> } catch (SQLException e) {
e.printStackTrace();
} finally {
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
if (stmt != null) {
try {
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
}
}
</code></pre>
<p>}
因为配置idea没整明白,所以代码还没运行起来
Original: https://www.cnblogs.com/333czh/p/15549761.html
Author: HelloHui
Title: JDBC学习
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/643154/
转载文章受原作者版权保护。转载请注明原作者出处!