壹咪陽光
BlogJava
首頁
新隨筆
聯系
聚合
管理
隨筆-124 評論-49 文章-56 trackbacks-0
BaseDAO
sql
package
org.epet.dao.impl;
import
java.sql.Connection;
import
java.sql.DriverManager;
import
java.sql.PreparedStatement;
import
java.sql.ResultSet;
import
java.sql.SQLException;
import
javax.naming.Context;
import
javax.naming.InitialContext;
import
javax.naming.NamingException;
import
javax.sql.DataSource;
import
com.sun.java_cup.internal.internal_error;
public
abstract
class
BaseDAO
{
private
static
final
String DRIVER_CLASS
=
"
com.microsoft.sqlserver.jdbc.SQLServerDriver
"
;
private
static
final
String DATABASE_URL
=
"
jdbc:sqlserver://localhost:1433;DatabaseName=epet
"
;
private
static
final
String DATABASE_USER
=
"
sa
"
;
private
static
final
String DATABASE_PASSWORD
=
"
accp
"
;
/** */
/**
* 返回連接
*
@return
*/
public
static
Connection getConnection()
{
Connection connection
=
null
;
try
{
Class.forName(DRIVER_CLASS);
connection
=
DriverManager.getConnection(DATABASE_URL,
DATABASE_USER, DATABASE_PASSWORD);
//
Context tx=new InitialContext();
//
DataSource ds=(DataSource)tx.lookup("java:comp/env/food");
//
connection=ds.getConnection();
}
catch
(SQLException e)
{
e.printStackTrace();
}
catch
(ClassNotFoundException e)
{
//
TODO Auto-generated catch block
e.printStackTrace();
}
return
connection;
}
/** */
/**
* 查詢
*
@param
sql
*
@return
*/
public
static
ResultSet getDate(String sql)
{
Connection connection
=
getConnection();
ResultSet resultSet
=
null
;
try
{
PreparedStatement preparedStatement
=
connection.prepareStatement(sql);
resultSet
=
preparedStatement.executeQuery();
}
catch
(SQLException e)
{
e.printStackTrace();
}
return
resultSet;
}
public
static
int
dele(String sql,
int
id)
{
int
result
=
0
;
Connection connection
=
getConnection();
try
{
PreparedStatement preparedStatement
=
connection.prepareStatement(sql);
preparedStatement.setInt(
1
, id);
result
=
preparedStatement.executeUpdate();
}
catch
(SQLException e)
{
e.printStackTrace();
}
return
result;
}
}
mysql:
/**/
/*
show databases;
create database aa;
use aa;
show tables;
select * from userinfo limit 1,2;
-----------------------------------------
*/
public
connection getConnection ()
throws
SQLException
{
Class.forName(
"
com.mysql.jdbc.Driver
"
);
String url
=
"
jdbc:mysql://127.0.1:3306/somken(數據庫名)
"
;
return
DriverManager.getConnection(url,
"
root
"
,
"
root
"
);
}
posted on 2009-11-30 08:21
junly
閱讀(528)
評論(0)
編輯
收藏
所屬分類:
oracle/mysql/sql
新用戶注冊
刷新評論列表
只有注冊用戶
登錄
后才能發表評論。
網站導航:
博客園
IT新聞
Chat2DB
C++博客
博問
管理
相關文章:
oracle游標
oracle控制語句
oracle函數大全
oracle變量
sql 精典-oracle
oracle存儲過程,函數,包
sql思路
配數據庫的方式
BaseDAO
sql配置文檔
<
2009年11月
>
日
一
二
三
四
五
六
25
26
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
常用鏈接
我的隨筆
我的評論
我的參與
最新評論
留言簿
(4)
給我留言
查看公開留言
查看私人留言
隨筆分類
ajax/jquery/js(23)
freemark/velocity(7)
hibernate/orm(20)
ide(5)
java(31)
jdbc/jndi(4)
jsp/servlet(17)
oracle/mysql/sql(12)
OS(2)
other(7)
spring(4)
struts2/struts1.3/JSF(34)
tomcat/jboss/weblogic(8)
xml/xsl/dtd/scherma
隨筆檔案
2011年5月 (3)
2011年3月 (1)
2010年11月 (1)
2010年8月 (2)
2010年7月 (8)
2010年6月 (3)
2010年5月 (2)
2010年4月 (5)
2010年3月 (1)
2010年2月 (6)
2010年1月 (7)
2009年12月 (11)
2009年11月 (110)
2009年10月 (20)
收藏夾
freemard(2)
other
ajax-js
facebox
flex
flex2
IBM中國- Java 技術
java2000
Java學習室
Java開源大全
linux 命令全集
Matrix 與Java共舞
tomcat中文網
web game
技術文檔
永遠的nuix
腳本之家
文章
Java API
JavaTM 2 Platform Standard Edition 5.0
URLRewriter
慎用url重寫
搜索
最新評論
1.?re: Java 7七大新功能預覽[未登錄]
shit@fa
--xxx
2.?re: 給Dreamweaver安裝jQuery插件jQuery_API.mxp
@12
想進來看看啊,不知道字數夠不夠
--文君
3.?re: jQuery-強大的jQuery選擇器 (詳解)[轉]
評論內容較長,點擊標題查看
--zuidaima
4.?re: hibernate基礎-Session_Flush
你怎么查到的>?>
--rejk
5.?re: jQuery-強大的jQuery選擇器 (詳解)[轉]
不錯,閱讀體驗很好。內容很充實
--化緣北辰
閱讀排行榜
1.?jQuery-強大的jQuery選擇器 (詳解)[轉] (103961)
2.?jquery radio取值,checkbox取值,select取值,radio選中,checkbox選中,select選中(22186)
3.?Java 7七大新功能預覽(16861)
4.?給Dreamweaver安裝jQuery插件jQuery_API.mxp(16413)
5.?開源框架Pushlet入門(6192)
評論排行榜
1.?jQuery-強大的jQuery選擇器 (詳解)[轉] (11)
2.?Java 7七大新功能預覽(9)
3.?給Dreamweaver安裝jQuery插件jQuery_API.mxp(5)
4.?米struts2的用戶請注意這個超級安全漏洞(3)
5.?dreamweaver cs4 許可證過期的解決辦法(3)
Powered by:
博客園
模板提供:
滬江博客
Copyright ©2025 junly
主站蜘蛛池模板:
永宁县
|
大英县
|
昭通市
|
吴堡县
|
白河县
|
台湾省
|
陕西省
|
平阳县
|
昭通市
|
固安县
|
铁力市
|
南丰县
|
宁乡县
|
潮安县
|
四川省
|
甘洛县
|
延川县
|
石阡县
|
隆安县
|
灯塔市
|
游戏
|
剑阁县
|
敦化市
|
滦平县
|
宣威市
|
公主岭市
|
张掖市
|
卢氏县
|
无为县
|
永登县
|
旌德县
|
全州县
|
武功县
|
兰坪
|
当涂县
|
云梦县
|
惠水县
|
太谷县
|
康保县
|
台中县
|
元朗区
|