傳統(tǒng)方式實(shí)現(xiàn)JAVA連接oracle數(shù)據(jù)庫(kù)
使用傳統(tǒng)方式連接oracle數(shù)據(jù)庫(kù)的話,可以在oracle數(shù)據(jù)庫(kù)中使用JAVA腳本,下面就為您介紹使用傳統(tǒng)方式連接oracle數(shù)據(jù)庫(kù)的方法,希望對(duì)您能有所啟迪。
此方法實(shí)現(xiàn)JAVA連接oracle數(shù)據(jù)庫(kù),其性能、可靠性與穩(wěn)定性隨著用戶訪問(wèn)量的增加逐漸下降,跟蹤測(cè)試表明,其根本問(wèn)題與Connection對(duì)象的創(chuàng)建有關(guān)。不過(guò)在這里還是講一下此方法的實(shí)現(xiàn):添加記錄到數(shù)據(jù)庫(kù)表中
- import java.sql.Connection;
 - import java.sql.DriverManager;
 - import java.sql.PreparedStatement;
 - String driver = "oracle.jdbc.driver.OracleDriver";
 - String url = "jdbc:oracle:thin:@192.168.1.3:1521:ora92";
 - String username = "scott";
 - String password = "tiger";
 - String sql = "insert into users(username,password) values (?,?)";
 - try {
 - Class.forName(driver); //oracle.jdbc.driver.OracleDriver();
 - Connection conn = DriverManager.getConnection(url, username,password);
 - PreparedStatement ps = conn.prepareStatement(sql); //Statement stat=conn.createStatement();
 - ps.setString(1, "張三");
 - ps.setString(2, "lisi");
 - ps.executeUpdate();
 - ps.close();
 - conn.close();
 - } catch (ClassNotFoundException e) {
 - e.printStackTrace();
 - } catch (SQLException e) {
 - e.printStackTrace();
 - }
 
【編輯推薦】















 
 
 

 
 
 
 