您的位置:首页 > 其它

JDBC的连接和操作

2016-10-17 22:57 99 查看
package Test;

import java.sql.*;

public class Test21 {
public static void main(String[] args) {
Connection con=null;
Statement sta=null;

try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con=DriverManager.getConnection("jdbc:sqlserver://localhost:1433;database=stuDB","sa","123456");
sta=con.createStatement();
String sql="insert useinfo values(1,'2','3')";
int result=sta.executeUpdate(sql);
System.out.println("ccc");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally
{
try {
con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: