2008-03-22
jdbc连接数据库例子
import java.sql.Connection;
import java.sql.Statement;
import java.sql.DriverManager;
public class DBTool {
private static Connection conn = null;
private static Statement stmt = null;
private static void getConn()
{
try
{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
conn = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=master;Uid=sa;Pwd=1234;","sa","1234");
}catch(Exception ex){ex.printStackTrace();}
}
public static boolean execSql(String sql){
boolean bool = false;
try{
getConn();
stmt = conn.createStatement();
bool = !stmt.execute(sql);
}catch(Exception ex){ex.printStackTrace();}
finally{
try {
if(!conn.isClosed()){
stmt.close();
}
} catch (Exception e) {e.printStackTrace();}
}
return bool;
}
}
import java.sql.Statement;
import java.sql.DriverManager;
public class DBTool {
private static Connection conn = null;
private static Statement stmt = null;
private static void getConn()
{
try
{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
conn = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=master;Uid=sa;Pwd=1234;","sa","1234");
}catch(Exception ex){ex.printStackTrace();}
}
public static boolean execSql(String sql){
boolean bool = false;
try{
getConn();
stmt = conn.createStatement();
bool = !stmt.execute(sql);
}catch(Exception ex){ex.printStackTrace();}
finally{
try {
if(!conn.isClosed()){
stmt.close();
}
} catch (Exception e) {e.printStackTrace();}
}
return bool;
}
}
发表评论
- 浏览: 3759 次
- 性别:

- 来自: 被遗忘的角落...

- 详细资料
搜索本博客
最新评论
-
改变Eclipse及NetBeans的 ...
一起努力吧!
-- by tcrct -
改变Eclipse及NetBeans的 ...
老唐,加油!
-- by 深秋小雨 -
spring+hibernate保存blob ...
getContentString()这个方法不行啊 ,不信你自己试试!
-- by kevlin -
spring+hibernate保存blob ...
在javabean里不是有一个getContentString()的方法吗?用这 ...
-- by tcrct -
spring+hibernate保存blob ...
好多都是想文件,跟图片的处理啊。可是我的是是超过10000个字的中文啊。那要是处 ...
-- by kevlin






评论排行榜