statement添加操作
来源:互联网 发布:电脑学影视制作软件 编辑:程序博客网 时间:2024/06/03 22:48
package mysql;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Sql {
static{
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
}
public static Connection getCon() throws SQLException{
Connection con=null;
try {
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/student","root","123456");
/*用connection获取数据库的连接*/
} catch (Exception e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
return con;
}
public static void main(String[] args) throws SQLException {
String sql="insert into studentmessage(name,xh,pwd,cla,age,籍贯,sex,hobby) values('玫瑰','1201','110','12','125','浙江省','男','玩蛇')";/*创建字符串sql=执行的sql*/
Connection con=getCon();/*获取connection方法*/
try {
Statement stmt=con.createStatement();
int i=stmt.executeUpdate(sql);
System.out.println(i+"行数据受到影响");
} catch (Exception e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}finally{
try {
con.close();/*关闭连接*/
} catch (Exception e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
}
}
}
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Sql {
static{
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
}
public static Connection getCon() throws SQLException{
Connection con=null;
try {
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/student","root","123456");
/*用connection获取数据库的连接*/
} catch (Exception e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
return con;
}
public static void main(String[] args) throws SQLException {
String sql="insert into studentmessage(name,xh,pwd,cla,age,籍贯,sex,hobby) values('玫瑰','1201','110','12','125','浙江省','男','玩蛇')";/*创建字符串sql=执行的sql*/
Connection con=getCon();/*获取connection方法*/
try {
Statement stmt=con.createStatement();
int i=stmt.executeUpdate(sql);
System.out.println(i+"行数据受到影响");
} catch (Exception e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}finally{
try {
con.close();/*关闭连接*/
} catch (Exception e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
}
}
}
0 0
- statement添加操作
- 使用 Statement 接口实现添加数据操作
- JDBC中Statement操作数据库 添加数据
- jdbc使用 Statement 接口实现添加数据操作小例子
- JDBC --Statement(添加)
- JDBC--Statement(删除操作)
- statement语句操作
- jdbc使用 Statement 接口实现添加数据操作(使用面向对象和数据库连接工具类)
- jdbc Statement和PrepareStatement操作
- statement与preparedStatement 批量操作
- JDBC--Statement(更新操作)
- JDBC通过Statement执行操作
- 批量添加和批量删除(statement.addBatch() )
- - Statement
- statement
- Statement
- statement
- statement
- postgresql监控工具pgstatspack的安装及使用
- LeetCode 110. Balanced Binary Tree 题解
- C#笔记(一)抽象方法、虚方法、接口
- Android 方形布局
- Java并发编程:线程池的使用(非常棒,通俗易懂)
- statement添加操作
- LeetCode No.65 ValidNumber
- 六自由度机械臂的驱动
- Spring学习总结(一)——Spring实现IoC的多种方式
- linux 下vi 命令使用
- python写网络爬虫:爬取糗事百科上的段子
- Webpack简单介绍
- Ret2Libc 攻击技术
- 如何在Activity中获取和设置控件的宽高