欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

java的數(shù)據(jù)庫代碼 JAVA數(shù)據(jù)庫編程

求Java數(shù)據(jù)庫代碼注釋

代碼主要列出連接數(shù)據(jù)庫的關(guān)鍵代碼,其他訪問數(shù)據(jù)庫代碼省略

目前成都創(chuàng)新互聯(lián)公司已為上千余家的企業(yè)提供了網(wǎng)站建設(shè)、域名、雅安服務(wù)器托管、網(wǎng)站托管、企業(yè)網(wǎng)站設(shè)計(jì)、河北網(wǎng)站維護(hù)等服務(wù),公司將堅(jiān)持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。

1、Oracle8/8i/9i數(shù)據(jù)庫(thin模式)

Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();

String url="jdbc:oracle:thin:@localhost:1521:orcl";

//orcl為數(shù)據(jù)庫的SID

String user="test";

String password="test";

Connection conn= DriverManager.getConnection(url,user,password);

2、DB2數(shù)據(jù)庫

Class.forName("com.ibm.db2.jdbc.app.DB2Driver ").newInstance();

String url="jdbc:db2://localhost:5000/sample";

//sample為你的數(shù)據(jù)庫名

String user="admin";

String password="";

Connection conn= DriverManager.getConnection(url,user,password);

3、Sql Server7.0/2000數(shù)據(jù)庫

Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();

String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=mydb";

//mydb為數(shù)據(jù)庫

String user="sa";

String password="";

Connection conn= DriverManager.getConnection(url,user,password);

4、Sybase數(shù)據(jù)庫

Class.forName("com.sybase.jdbc.SybDriver").newInstance();

String url =" jdbc:sybase:Tds:localhost:5007/myDB";

//myDB為你的數(shù)據(jù)庫名

Properties sysProps = System.getProperties();

SysProps.put("user","userid");

SysProps.put("password","user_password");

Connection conn= DriverManager.getConnection(url, SysProps);

5、Informix數(shù)據(jù)庫

Class.forName("com.informix.jdbc.IfxDriver").newInstance();

String url =

"jdbc:informix-sqli://123.45.67.89:1533/myDB:INFORMIXSERVER=myserver;

user=testuser;password=testpassword";

//myDB為數(shù)據(jù)庫名

Connection conn= DriverManager.getConnection(url);

6、MySQL數(shù)據(jù)庫

Class.forName("org.gjt.mm.mysql.Driver").newInstance();

String url ="jdbc:mysql://localhost/myDB?user=softpassword=soft1234useUnicode=truecharacterEncoding=8859_1"

//myDB為數(shù)據(jù)庫名

Connection conn= DriverManager.getConnection(url);

7、PostgreSQL數(shù)據(jù)庫

Class.forName("org.postgresql.Driver").newInstance();

String url ="jdbc:postgresql://localhost/myDB"

//myDB為數(shù)據(jù)庫名

String user="myuser";

String password="mypassword";

Connection conn= DriverManager.getConnection(url,user,password);

用java編寫一個(gè)創(chuàng)建數(shù)據(jù)庫和表的程序的代碼怎么寫

import?java.sql.*;

public?class?Test

{

public?static?void?main(String[]?args)?throws?Exception

{

Class.forName("com.mysql.jdbc.Driver");

//一開始必須填一個(gè)已經(jīng)存在的數(shù)據(jù)庫

String?url?=?"jdbc:mysql://localhost:3306/test?useUnicode=truecharacterEncoding=utf-8";????

Connection?conn?=?DriverManager.getConnection(url,?"root",?"123456");

Statement?stat?=?conn.createStatement();

//創(chuàng)建數(shù)據(jù)庫hello

stat.executeUpdate("create?database?hello");

//打開創(chuàng)建的數(shù)據(jù)庫

stat.close();

conn.close();

url?=?"jdbc:mysql://localhost:3306/hello?useUnicode=truecharacterEncoding=utf-8";

conn?=?DriverManager.getConnection(url,?"root",?"123456");

stat?=?conn.createStatement();

//創(chuàng)建表test

stat.executeUpdate("create?table?test(id?int,?name?varchar(80))");

//添加數(shù)據(jù)

stat.executeUpdate("insert?into?test?values(1,?'張三')");

stat.executeUpdate("insert?into?test?values(2,?'李四')");

//查詢數(shù)據(jù)

ResultSet?result?=?stat.executeQuery("select?*?from?test");

while?(result.next())

{

System.out.println(result.getInt("id")?+?"?"?+?result.getString("name"));

}

//關(guān)閉數(shù)據(jù)庫

result.close();

stat.close();

conn.close();

}

}

一段java中數(shù)據(jù)庫代碼解釋

StringBuffer

sqlq=new

StringBuffer("

SELECT

*

FROM

")

;//申明一個(gè)可變字符串

,要存了一個(gè)sql語句,并且由"

SELECT

*

FROM

"可知其為一個(gè)select查詢語句

sqlq.append(DtoMapGroupOptions.DB_TABLE_NAME)

;//DtoMapGroupOptions.DB_TABLE_NAME應(yīng)該是一個(gè)字符串,字面值為一個(gè)表的名稱,要在這個(gè)表里查數(shù)據(jù)

sqlq.append("

ORDER

BY

")

;//這個(gè)制定查出來的結(jié)果集需要排序

sqlq.append(DtoMapGroupOptions.COLUMN_optionID)

;//DtoMapGroupOptions.COLUMN_optionID應(yīng)該是某一列的列名,根據(jù)這一列來排序,如果這一列是數(shù)字,那么就會(huì)根據(jù)數(shù)字大小排,字符串可能按abc排,和excel排序時(shí)一樣的,即根據(jù)某一列來擴(kuò)展至整個(gè)區(qū)域排序

sqlq.append("

DESC

")

;//這個(gè)事制定按降序還是升序,這里是降序

//后面的語句要看上下文,那個(gè)pb不知是什么

ListRow

list

=

null

;

pb.isRequireTotalRow(true);

String

sqlStr=sqlq.toString();

list

=

pb.getInfo(sqlStr,

null,

DtoMapGroupOptions.DATA_SOURCE_ID);//可能是把結(jié)果集放入list中,根據(jù)sqlStr中的sql語句

java連接數(shù)據(jù)庫的代碼

用這個(gè)類吧.好的話,給我加加分.

import java.sql.*;

/**

* @功能: 一個(gè)JDBC的本地化API連接類,封裝了數(shù)據(jù)操作方法,只用傳一個(gè)SQL語句即可

* @作者: 李開歡

* @日期: 2007/

*/

public class ConnectionDemo {

/*

* 這里可以將常量全部放入另一個(gè)類中,以方便修改

*/

private static Connection conn;

private static Statement ps;

private static ResultSet rs;

private static final String DRIVER = "com.microsoft.jdbc.sqlserver.SQLServerDriver";

private static final String URL = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=mydb";

private static final String USER ="sa";

private static final String PASS = "sa";

public ConnectionDemo() {

// TODO Auto-generated constructor stub

ConnectionDemo.getConnection();

}

public static Connection getConnection(){

System.out.println("連接中...");

try {

Class.forName(ConnectionDemo.DRIVER);

conn = DriverManager.getConnection(ConnectionDemo.URL, ConnectionDemo.USER, ConnectionDemo.PASS);

System.out.println("成功連接");

} catch (ClassNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

return conn;

}

public static Statement getStatement(String sql){

System.out.println("執(zhí)行SQL語句中...");

try {

ps = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);

if(sql.substring(0, 6).equals("select")){

rs = ps.executeQuery(sql);

System.out.println("執(zhí)行完查詢操作,結(jié)果已返回ResultSet集合");

}else if(sql.substring(0, 6).equals("delete")){

ps.executeUpdate(sql);

System.out.println("已執(zhí)行完畢刪除操作");

}else if(sql.substring(0, 6).equals("insert")){

ps.executeUpdate(sql);

System.out.println("已執(zhí)行完畢增加操作");

}else{

ps.executeUpdate(sql);

System.out.println("已執(zhí)行完畢更新操作");

}

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

return ps;

}

public static ResultSet getResultSet(){

System.out.println("查詢結(jié)果為:");

return rs;

}

public static void closeConnection(){

System.out.println("關(guān)閉連接中...");

try {

if (rs != null) {

rs.close();

System.out.println("已關(guān)閉ResultSet");

}

if (ps != null) {

ps.close();

System.out.println("已關(guān)閉Statement");

}

if (conn != null) {

conn.close();

System.out.println("已關(guān)閉Connection");

}

} catch (Exception e) {

// TODO: handle exception

}

}

public static void main(String[] args) {

// TODO Auto-generated method stub

ConnectionDemo.getConnection();

String sql = "delete from type where id = 1";

ConnectionDemo.getStatement(sql);

String sql2 = "insert into type values(1,'教學(xué)設(shè)備')";

ConnectionDemo.getStatement(sql2);

String sql1 = "select * from type";

ConnectionDemo.getStatement(sql1);

ResultSet rs = ConnectionDemo.getResultSet();

System.out.println("編號(hào) "+"類 型");

try {

while(rs.next()){

System.out.print(" "+rs.getInt(1)+" ");

System.out.println(rs.getString(2));

}

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

ConnectionDemo.closeConnection();

}

}

JAVA連接數(shù)據(jù)庫連接代碼怎么寫?

1 將數(shù)據(jù)庫的JDBC驅(qū)動(dòng)加載到classpath中,在基于JAVAEE的WEB應(yīng)用實(shí)際開發(fā)過程中,通常要把目標(biāo)數(shù)據(jù)庫產(chǎn)品的JDBC驅(qū)動(dòng)復(fù)制到WEB-INF/lib下.

2 加載JDBC驅(qū)動(dòng),并將其注冊(cè)到DriverManager中,下面是一些主流數(shù)據(jù)庫的JDBC驅(qū)動(dòng)加裁注冊(cè)的代碼:

//Oracle8/8i/9iO數(shù)據(jù)庫(thin模式)

Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();

//Sql Server7.0/2000數(shù)據(jù)庫

Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();

//DB2數(shù)據(jù)庫

Class.froName("com.ibm.db2.jdbc.app.DB2Driver").newInstance();

//Informix數(shù)據(jù)庫

Class.forName("com.informix.jdbc.IfxDriver").newInstance();

//Sybase數(shù)據(jù)庫

Class.forName("com.sybase.jdbc.SybDriver").newInstance();

//MySQL數(shù)據(jù)庫

Class.forName("com.mysql.jdbc.Driver").newInstance();

//PostgreSQL數(shù)據(jù)庫

Class.forNaem("org.postgresql.Driver").newInstance();

3 建立數(shù)據(jù)庫連接,取得Connection對(duì)象.例如:

//Oracle8/8i/9i數(shù)據(jù)庫(thin模式)

String url="jdbc:oracle:thin:@localhost:1521:orcl";

String user="scott";

String password="tiger";

Connection conn=DriverManager.getConnection(url,user,password);

--完整的太多了!我已經(jīng)把完整的代碼發(fā)到你QQ郵箱了!

分享文章:java的數(shù)據(jù)庫代碼 JAVA數(shù)據(jù)庫編程
分享URL:http://chinadenli.net/article28/dodcecp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供響應(yīng)式網(wǎng)站、ChatGPT、微信公眾號(hào)、移動(dòng)網(wǎng)站建設(shè)、手機(jī)網(wǎng)站建設(shè)、企業(yè)建站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

手機(jī)網(wǎng)站建設(shè)