導航:首頁 > 編程語言 > java資料庫配置文件

java資料庫配置文件

發布時間:2022-06-28 19:27:44

『壹』 資料庫配置文件怎麼填寫

一般放置在配置文件中按以下方式樓主寫的app.config使用Web.config是相同的節點
<新增名稱=「資料庫」
的connectionString
=「供應商=
Microsoft.Jet。
OLEDB.4.0;數據源=數據\
data.mdb中「
的providerName
=」System.Data.OleDb「p>
程序這樣的引用ConfigurationManager中。
。的ConnectionStrings
[「資料庫」]的ConnectionString;注意添加引用

『貳』 資料庫配置文件是哪一個

配置資料庫配置文件的方法: 1.首先先創建一個db.properties的配置文件。在配置文件中輸入配置信息如下: driver=com.microsoft.sqlserver.jdbc.SQLServerDriver url=jdbc:sqlserver://localhost:1433;DatabaseName=books user=sa password=sa 2.創建一個載入db.properties的文件Env.java。在java文件中載入配置信息如下: public class Evn extends Properties{ private static Evn instance; private Evn(){ //通過構造方法讀取配置文件 InputStream is=getClass().getResourceAsStream("/db.properties"); try { load(is); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static Evn getInstance(){ //單例模式創建、獲得對象實例。if(instance==null){ makeInstance(); } return instance; } public static synchronized void makeInstance() { if(instance==null){ instance=new Evn(); } } } 3.讀取數據方法 public class Test { public static void main(String[] args){ String driver=Env.getInstance().getProperty("driver"); String url=Env.getInstance().getProperty("url"); String user=Env.getInstance().getProperty("user"); String password=Env.getInstance().getProperty("password"); System.out.println(driver); System.out.println(url); System.out.println(user); System.out.println(password); } }

『叄』 請各位java高手給我一個java資料庫配置文件.急急.謝謝!

我是用的
String
url
="jdbc:odbc:Driver={Microsoft
Access
Driver
(*.mdb)};DBQ=C:\\Tmp.mdb";
//載入驅動程序
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//建立連接
Connection
conn=
DriverManager.getConnection(url);
//創建語句對象
Statement
stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
但是這個路徑指向的是伺服器上的路徑,不是我本機的
A:
url
=
"jdbc:odbc:driver={Microsoft
Access
Driver
(*.mdb)};DBQ=C:\\Tmp.mdb";
我知道用上面這個方法可以連接本地的Access,與ODBC-JDBC橋是一樣的
應該要寫IP,因為你最終要找的是一個文件,路徑就得是一個有效的本地路徑或者網路路徑.
我做了測試
String
url
=
"jdbc:odbc:Driver={Microsoft
Access
Driver
(*.mdb)};DBQ=\\\\192.168.1.49\\apache\\Tmp.mdb";
這個也可以有,一樣連通了
就是你在伺服器上把文件夾共享,只要能找到這個文件就可以.但不推薦這個用網路的,有可能因為網路許可權而導致連接錯誤,等一些莫名錯誤,

『肆』 java怎麼連接資料庫配置文件

你是說properties文件嗎?

//讀取配置文件DbUtil.properties,這里的DbUtil是此文件里的一個類,就是當前類
p.load(DbUtil.class.getClassLoader().getResourceAsStream("DbUtil.properties"));

//獲取配置文件中的相關參數值
driver=p.getProperty("mysqlDriver");
url=p.getProperty("mysqlUrl");
user=p.getProperty("mysqlUser");
password=p.getProperty("mysqlPassword");

這里是DbUtil.properties文件里的內容:

##oracledatabase
oracleDriver=oracle.jdbc.driver.OracleDriver
oracleUrl=jdbc:oracle:thin:@localhost:1521:orcl
oracleUser=scott
oraclePassword=tiger

##mysqldatabase
mysqlDriver=com.mysql.jdbc.Driver
mysqlUrl=jdbc:mysql://localhost:3306/db_test
mysqlUser=root
mysqlPassword=root

『伍』 java使用Mysql資料庫要怎麼配置

需要,個人覺得jdbc 是比其他的方便
舉例來說:
我用的java的編輯器是jcreator pro 資料庫為 mysql
那麼你只需在mysql官方網站上下載一個windows 的mysqljdbc 然後把解壓
jdk路徑下的jre下的ext中 然後在jcreator pro中"配置"菜單下的jdk設置中編輯添加下載來的mysql_jdbc.rar的位元組碼文件 即可用了

『陸』 javaWeb工程資料庫配置文件加解密問題

這個有幾個思路:
一個是本身項目文件應該有訪問許可權限制,生產環境的系統不應讓開發人員可以察看,開發環境和生產環境應分開。

如果不能分開,還有個方法是用J2EE伺服器容器提供資料庫Datasource,應用程序直接從web容器獲取,不需要提供用戶名密碼。

還有一個方法,配置資料庫伺服器限制用戶只能從Web容器IP連接,這樣甚至可以不需要密碼。

『柒』 求助高手幫我解決java中連接資料庫時配置文件的問題,總是拋出空指針的異常

this.driver = prop.getProperty(driver);
是這行拋異常了,看異常也能找到。是你帶嗎的第20行。
是你的prop是空對象,說明:
InputStream is = this.getClass().getResourceAsStream(
"dbconfig.properties");
Properties prop = new Properties();
沒有讀取到配置文件,請仔細檢查配置文件是否存在。
如果是在src根目錄里 加
InputStream is = this.getClass().getResourceAsStream(
"classpath:dbconfig.properties");

『捌』 Java資料庫連接池的幾種配置方法(以MySQL數

連接先建立一些連接,並且這些連接允許共享,因此這樣就節省了每次連接的時間開銷。Mysql資料庫為例,連接池在Tomcat中的配置與使用。
1、創建資料庫Student,表student
2、配置server.xml文件。Tomcat安裝目錄下conf中server.xml文件。
<GlobalNamingResources>
<Resource
name="jdbc/DBPool"
type="javax.sql.DataSource"
password=""
driverClassName="com.mysql.jdbc.Driver"
maxIdle="2"
maxWait="5000"
username="root"
url="jdbc:mysql://localhost:3306/student"
maxActive="3"
/>
</GlobalNamingResources>
name:指定連接池的名稱
type:指定連接池的類,他負責連接池的事務處理
url:指定要連接的資料庫
driverClassName:指定連接資料庫使用的驅動程序
username:資料庫用戶名
password:資料庫密碼
maxWait:指定最大建立連接等待時間,如果超過此時間將接到異常
maxIdle:指定連接池中連接的最大空閑數
maxActive:指定連接池最大連接數
3、配置web.xml文件。
<web-app>
<resource-ref>
<description>mysql資料庫連接池配置</description>
<res-ref-name>jdbc/DBPool</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
</web-app>
4、配置context.xml文件
與server.xml文件所在的位置相同。
<Context>
<ResourceLink
name="jdbc/DBPool"
type="javax.sql.DataSource"
global="jdbc/DBPool"
/>
</Context>
5、測試
DataSource pool = null;
Context env = null;
Connection conn = null;
Statement st = null;
ResultSet rs = null;
try{
env = (Context)new InitialContext().lookup("java:comp/env");
//檢索指定的對象,返回此上下文的一個新實例
pool = (DataSource)env.lookup("jdbc/DBPool");
//獲得資料庫連接池
if(pool==null){out.printl("找不到指定的連接池!");}
con = pool.getConnection();
st = con.createStatement();
rs = st.executeQuery("select * from student");
}catch(Exception ex){out.printl(ne.toString());}

『玖』 java 配置資料庫文件是哪個文件

java本身並沒有規定資料庫配置文件必須寫到哪個文件中。開發者自己決定。tomcat的資料庫配置一般寫到server.xml中,但不是絕對的。

『拾』 java 中如何寫資料庫連接字元竄的properties配置文件

單獨定義一個文件:DBConfig.properties
driver=com.microsoft.jdbc.sqlserver.SQLServerDriver
url=jdbc:microsoft:sqlserver://localhost:1433;databasename=dbName
user=sa
password=
調用這些信息連接來資料庫.一般是在類里.
ResourceBundle bundle = ResourceBundle.getBundle("DBConfig");
String driver = bundle.getString("driver");
String url = bundle.getString("url");
String user = bundle.getString("user");
String password = bundle.getString("password");

try {
Class.forName(driver);
conn = DriverManager.getConnection(url, user, password);
} catch (ClassNotFoundException e) {
System.out.println(e.getMessage());
} catch (SQLException e) {
System.out.println(e.getMessage());
}
驗證用戶登陸其實就是一個查詢方法,根據頁面取出的內容.做個equals()判斷就可以了.

閱讀全文

與java資料庫配置文件相關的資料

熱點內容
設計道pdf 瀏覽:615
單片機kill4軟體下載收費嗎 瀏覽:846
蘋果手機怎麼連接RMS伺服器 瀏覽:603
cisco路由器基本配置命令 瀏覽:186
android狀態欄顏色透明 瀏覽:116
db2編譯工具 瀏覽:181
騰訊雲伺服器創建環境 瀏覽:567
監管資金怎麼解壓 瀏覽:671
榮耀手機內存清理文件夾 瀏覽:175
外派程序員方案 瀏覽:554
安卓怎麼把桌面的軟體變成卡通 瀏覽:885
魯班鎖解壓嗎 瀏覽:395
打包發送文件如何加密 瀏覽:213
centos解壓縮zip 瀏覽:388
我的世界怎麼用命令風塊取消指令 瀏覽:1000
安卓軟體請求超時怎麼辦 瀏覽:476
androidapp調用另一個app 瀏覽:621
數控銑床法蘭克子程序編程 瀏覽:174
linux打包命令targz 瀏覽:997
抖音app是哪個 瀏覽:407