JDBC判断数据库是否插入成功

package com.xujianyou;

import java.sql.*;

public class TestConnect {
public static void main(String []args) {
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs";
String user = "sa";
String password = "da";
Connection con = DriverManager.getConnection(url, user, password);
Statement sta = con.createStatement();
int result = sta.executeUpdate();
if (result > 0) {
//证明成功插入啊.你就可以在这里写你想写的动作
}
else {
//插入失败!
}
} catch(Exception e){
e.printStackTrace();
}
}
}
上一篇:基于Nginx+redis的Asp.net站点搭建


下一篇:pythoncharm 中解决启动server时出现 “django.core.exceptions.ImproperlyConfigured: Requested setting DEBUG, but settings are not configured”的错误