JDBC连接sql server 2008数据库

news/2024/7/7 10:12:23
public class TestJdbc {
public static void main(String[] args) {
// 定义需要的对象
PreparedStatement ps = null;
Connection ct = null;
ResultSet rs = null;
try {
// 初始化我们的对象
// 1.加载驱动
// Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
// 2.得到连接( 这里的1368为动态端口号,也解决Java找不到sqljdbc_auth.dll的问题
ct = DriverManager
.getConnection(
"jdbc:sqlserver://127.0.0.1:1368;DatabaseName=shudiansuo;authenticationScheme=JavaKerberos;",
"sa", "woaifr0828");
// 3.创建火箭车
ps = ct.prepareStatement("select * from shudiansu");
// 4.执行
rs = ps.executeQuery();


while (rs.next()) {
String id = rs.getString("id");
String randnumber = rs.getString(1);
System.out.println("id="+id+"randrnumber=" + randnumber);
}
//添加,删除,更新
//3.创建火箭筒
ps=ct.prepareStatement("insert into shudiansu values(102,600)");

int i = ps.executeUpdate();
if(i==1){
System.out.println("执行ok");
}else{
System.out.println("执行不ok");
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {


}
}
}

http://www.niftyadmin.cn/n/3649398.html

相关文章

如何使用React-Lottie将动画添加到React应用

介绍 (Introduction) Adobe After Effects can be an intuitive way to generate web animations, but there has historically been problems converting these animations to web apps. It is usually necessary to use a third party program to import an animation from A…

Android系统常用隐藏命令大全

本文出自:http://androidkaifa.com/thread-1038-1-1.html android手机隐藏命令大全,用之前要考虑清楚尤其是涉及到格式化或者恢复出厂设置类的! 注意:因Android版本较多,固有部分隐藏命令或不能使用(笔者用…

WordPress文本工具实现代码执行功能

WordPress自带有两个小工具可以执行代码功能。一个是自定义HTML小工具,不过只能运行HTML、CSS、JavaScript三种语言。文本小工具默认是不可以运行代码的。要实现这个功能,需要添加以下代码。 使用方法:在当前主题目录下面的functions.php里面…

[LCS]启用WindowsMessenger5.0的调试日志功能来诊断登录LCS服务器

编写者:郑昀UltraPower摘要:Windows Messenger 5.0有一个注册表项设置,可以用来启用日志文件,该文件中记录了Windows Messenger 5.0登录LCS Server的详细来往包,可从其中得到通讯细节,从而作troubleshootin…

解决GridView与scrollview嵌套时GridView显示一行数据

重写GridView的onMeasure的方法: public class MyGridView extends GridView { public MyGridView(Context context, AttributeSet attrs) { super(context, attrs); } public MyGridView(Context context) { super(context); } public MyGridView(Context context, Attri…

如何通过npm和package.json使用Node.js模块

The author selected the Open Internet/Free Speech Fund to receive a donation as part of the Write for DOnations program. 作者选择了“ 开放互联网/言论自由基金会”作为“ Write for DOnations”计划的一部分来接受捐赠。 介绍 (Introduction) Because of such featu…

Android系统获取手机型号和系统版本号,以及其他配置信息

<pre name"code" class"java">String sdkandroid.os.Build.VERSION.SDK; // SDK号 String modelandroid.os.Build.MODEL; // 手机型号 String releaseandroid.os.Build.VERSION.RELEASE; // android系统版本号执行以下代码前&#xff0c;须在manifes…

网页模块实现电脑端显示(隐藏)手机端隐藏(显示)

在开发的很多时候&#xff0c;遇到有些模块在电脑端显示正常&#xff0c;而到手机端就显示不正常&#xff0c;或者有些模块只想在电脑或手机一端显示。另一端不显示。这个就要用到HTMLCSS的隐藏功能了。 1、电脑端显示&#xff0c;手机端隐藏&#xff0c;以下是CSS样式&#xf…