導航:首頁 > 源碼編譯 > jdbc分庫源碼

jdbc分庫源碼

發布時間:2022-06-07 07:31:30

Ⅰ 如何找到mysql-jdbc驅動源碼

在工程中右鍵新建file,命名為jdbc.properties

創建完畢如圖:

在jdbc.properties文件中輸入如下信息,分別是資料庫的驅動,連接,用戶名和密碼

新建JdbcTest2.java

輸入如下代碼:

代碼說明:
這段代碼是讀取配置文件,把配置文件中的各個項通過名稱讀取出來

這段代碼是通過反射來創建Driver對象,反射就是類的實例化

在主函數中輸入如下,測試方法

運行之後的結果如下,表示連接成功!

Ⅱ 你有一個簡單的資料庫的源代碼嗎最好用Java實現的...

class ConnectionProvider{
private static String JDBC_DRIVER;
private static String DB_URL;
private static String DB_USER;
private static String DB_PASSWORD;

public ConnectionProvider()
{
JDBC_DRIVER = "com.mysql.jdbc.Driver"
DB_URL = "jdbc:mysql://localhost:3306/u-disk";
DB_USER = "root";
DB_PASSWORD = "root"
};
public Connection getConnection()
{
try {
Class.forName(JDBC_DRIVER);
} catch (Exception e) {
System.out.println("驅動文件路徑有誤!");
}
}
Connection con = null;
try {
con = DriverManager.getConnection(DB_URL, DB_USER,
DB_PASSWORD);
} catch (SQLException e) {
System.out.println("資料庫連接建立異常!\n@shy2850@" + e.getMessage() +
e.getCause());
}
System.out.println("得到連接:Connection " + ConnectionPool.connections.size() + 1);
return new ConnectionImpl(con);
}
}

可以使用這個包裝的資料庫連接數據源在DAO工具類中使用:

package com.jdbc;

import java.sql.*;

/**課題:封裝資料庫的增刪改查的工具類的實現。
*
* 假設相關資料庫的表結構如下:
* 表名:user
* 列名及屬性:id(int 自增),name(varchar(20)),tele(char(12)),birthday(date)
* @author shy2850
*/
public class UserDAO {

Connection conn;

public UserDAO(Connection conn) {
this.conn = conn;
}

public int save(User user) throws SQLException {
String sql = "insert into user values(0,?,?,?)";
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setString(1, user.getName());
pstmt.setString(2, user.getTele());
pstmt.setDate(3, user.getBirthday());
int n = pstmt.executeUpdate();
pstmt.close();
return n;
}

public int delete(User user) throws SQLException{
String sql = "delete from user where id = "+user.getId();
Statement stmt = conn.createStatement();
int n = stmt.executeUpdate(sql);
stmt.close();
return n;
}

public int update(User user) throws SQLException{
String sql = "update user set name=?, tele=?, birthday=? where id = "+user.getId();
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setString(2, user.getName());
pstmt.setString(3, user.getTele());
pstmt.setDate(4, user.getBirthday());
int n = pstmt.executeUpdate(sql);
pstmt.close();
return n;
}

public User getUser(Integer id) throws SQLException{
String sql = "select * from user where id = " + id;
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
User user = getUserFromResultSet(rs);
rs.close();
stmt.close();
return user;
}

static User getUserFromResultSet(ResultSet rs) throws SQLException{
Integer id = rs.getInt("id");
String name= rs.getString("name");
String tele= rs.getString("tele");
Date birthday = rs.getDate("birthday");
return new User(id, name, tele, birthday);
}
}
/**
* 構建資料庫表的java類映射
*/
class User{
private Integer id;
private String name;
private String tele;
private Date birthday;

public User() {
}
public User(Integer id, String name, String tele, Date birthday) {
super();
this.id = id;
this.name = name;
this.tele = tele;
this.birthday = birthday;
}

public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getTele() {
return tele;
}

public void setTele(String tele) {
this.tele = tele;
}

public Date getBirthday() {
return birthday;
}

public void setBirthday(Date birthday) {
this.birthday = birthday;
}
}

Ⅲ oracle jdbc驅動源代碼

可以用JD-GUI反編譯jar

Ⅳ 求一個簡單又經典的JAVA資料庫連接的例子,要有源代碼哦!

我就弄的用戶登入的代碼吧.這個挺簡單的.
這是題目:
用戶登陸驗證:
1.創建資料庫Test,並新建用戶表users
欄位包含:username varchar(20) not null
userpwd varchar(20) not null

在JBUILDER中編寫Long類,實現登陸界面,並在用戶輸入用戶名和密碼後,
完成按紐的單擊事件,對用戶輸入的數據進行驗證,
(需要嚴整數據是否為空,密碼長度必須是15位),
並實現與資料庫的連接,將用戶輸入的用戶名密碼與表中的記錄比較,
若用戶名正確且密碼正確,彈出提示框告知登陸成功,否則登陸失敗。

這是代碼:
//連接資料庫
boolean isLogin(String name,String pwd){
boolean flag=false;
Connection conn=null;
PreparedStatement pst=null;
ResultSet rs=null;
//載入驅動
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
}
//連接資料庫
try {
conn=DriverManager.getConnection("jdbc:odbc:login");
String sql="select * from [user] where username=? and userpwd=?";
pst=conn.prepareStatement(sql);
pst.setString(1,name);
pst.setString(2,pwd);
rs=pst.executeQuery();
if(rs.next())
flag=true;
} catch (Exception ex) {
ex.printStackTrace();
}finally{
try {
conn.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
return flag;

}
//驗證方法
public void jButton1_actionPerformed(ActionEvent e) {
String name=jTextField1.getText();
String pwd=jTextField2.getText();
//錯誤處理
if(name.equals("")||pwd.equals(""))
JOptionPane.showMessageDialog(this,"請輸入完整的信息");
else {
if(isLogin(name,pwd))
JOptionPane.showMessageDialog(this,"登陸成功");
else
JOptionPane.showMessageDialog(this,"用戶名或密碼錯誤");

}

}
}
.....
.....
這是在事件里寫的,

Ⅳ 用JAVA編程的通過SQL連接資料庫的商品庫存管理系統的源代碼

導jar包,你給我郵箱我給你發一個jar包....

Ⅵ 求 Spring3.1.1源碼,最好全部,最重要的是jdbc那部分的源碼

jdbc和連接池對於你這個場景來說,都足夠,既然用spring管理了,建議還是使用連接池,另外,spring自身沒有實現連接池,一般都是對第三方連接池的包裝,常見的有C3P0,dbcp以及最近比較流行的boneCP等,這幾個配置都差不多太多,以boneCP為例:
<bean id="dataSource" class="com.jolbox.bonecp.BoneCPDataSource"
destroy-method="close">
<property name="driverClass" value="${jdbc.driverClass}" />
<property name="jdbcUrl" value="${jdbc.url}" />
<property name="username" value="${jdbc.user}" />
<property name="password" value="${jdbc.password}" />
<property name="idleConnectionTestPeriod" value="60" />
<property name="idleMaxAge" value="240" />
<property name="maxConnectionsPerPartition" value="30" />
<property name="minConnectionsPerPartition" value="10" />
<property name="partitionCount" value="2" />
<property name="acquireIncrement" value="5" />
<property name="statementsCacheSize" value="100" />
<property name="releaseHelperThreads" value="3" />
</bean>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource" />
</bean>

Ⅶ 急!求JDBC源代碼

我剛做了一個固定資產的項目~五千多行代碼~不知道可行·行的話給你發代碼~

閱讀全文

與jdbc分庫源碼相關的資料

熱點內容
華為mml命令查看用戶量 瀏覽:905
場論朗道pdf 瀏覽:369
如何使用qtquick編譯器 瀏覽:46
山西高配伺服器雲伺服器 瀏覽:740
為什麼編譯按f9沒反應 瀏覽:118
購物app都適合買什麼東西 瀏覽:273
savetxt函數python 瀏覽:573
編譯器小端改大端 瀏覽:638
華為安卓哪些文件夾能刪除 瀏覽:402
手機samp伺服器地址 瀏覽:205
phpformat函數 瀏覽:563
單片機由線 瀏覽:591
如何查找方舟編譯過的app 瀏覽:897
青山有什麼做演算法的公司 瀏覽:568
硬體編譯原理圖 瀏覽:162
程序員技術總監 瀏覽:72
程序員網易雲報告 瀏覽:463
studio編譯功能在哪裡 瀏覽:242
空氣壓縮機尺寸 瀏覽:988
sockethttpsphp 瀏覽:488