没有合适的资源?快使用搜索试试~ 我知道了~
JDBC连接SQL Server2008插入、修改、删除、查询代码
5星 · 超过95%的资源 需积分: 19 131 下载量 39 浏览量
2012-02-23
19:57:47
上传
评论 2
收藏 4KB TXT 举报
温馨提示
试读
5页
JDBC连接SQL Server2008 插入、修改、删除、查询操作的示例代码
资源推荐
资源详情
资源评论
插入数据
import java.sql.*;
/**
* @version 2012-02-22
* @author
*/
public class InsertDemo {
public static void main(String[] args) throws SQLException {
Connection conn = null;
Statement stmt = null;
String JDriver="com.microsoft.sqlserver.jdbc.SQLServerDriver";//SQL鏁版嵁搴撳紩鎿�
String connectDB="jdbc:sqlserver://localhost:1433;DatabaseName=JDBCTest";//鏁版嵁婧惵�
String user="sa";
String pwd="sql";
try {
// 动态导入数据库的驱动
Class.forName(JDriver);
// 获取数据库链接
conn = DriverManager.getConnection(connectDB,user,pwd);
// 创造SQL语句
String sql = "INSERT INTO JDBCTestTable ( user_name, user_password ) VALUES ( 'balabala', '123456' )";
// 执行SQL语句
stmt = conn.createStatement();
stmt.executeUpdate(sql);
System.out.println("插入数据成功");
} catch (Exception e) {
e.printStackTrace();
stmt.close();
conn.close();
import java.sql.*;
/**
* @version 2012-02-22
* @author
*/
public class InsertDemo {
public static void main(String[] args) throws SQLException {
Connection conn = null;
Statement stmt = null;
String JDriver="com.microsoft.sqlserver.jdbc.SQLServerDriver";//SQL鏁版嵁搴撳紩鎿�
String connectDB="jdbc:sqlserver://localhost:1433;DatabaseName=JDBCTest";//鏁版嵁婧惵�
String user="sa";
String pwd="sql";
try {
// 动态导入数据库的驱动
Class.forName(JDriver);
// 获取数据库链接
conn = DriverManager.getConnection(connectDB,user,pwd);
// 创造SQL语句
String sql = "INSERT INTO JDBCTestTable ( user_name, user_password ) VALUES ( 'balabala', '123456' )";
// 执行SQL语句
stmt = conn.createStatement();
stmt.executeUpdate(sql);
System.out.println("插入数据成功");
} catch (Exception e) {
e.printStackTrace();
stmt.close();
conn.close();
xiaoliangmei
- 粉丝: 34
- 资源: 11
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
前往页