開發系統學習(一)

來源:互聯網
上載者:User

上天是公平的,世上的每一個人都是一天24個小時的存留時間。八個小時睡覺,八小時工作,而真正取決於你自己的能力的是另外的八個小時。這是在一個朋友的微博上看到的,以激勵自己去努力學習。選擇程式員這條路據需要每天努力去學習,“生於憂患死於安樂”,我相信每一份的付出都會有收穫的。首先,結束了系統的設計階段,開始了編碼,一總結每一階段的學習與大家分享,還望大家提出意見和建議,我們共同學習進步。

這個系統整體是用MyEclipse8.5 和SQl server 2005來做的

首先在Java開發中多用的是oracle資料庫,其實都是一樣的,JdbC中使用oracle資料庫classPath的是class12.jar而sqlserver中classpath的是sqljdbc.jar(可以到我的部落格資源裡下載)

下面我們就開始詳細介紹JAva開發中怎樣串連sql server 資料庫吧。

代碼如下

public Connection conn(){//載入驅動String driverName="com.microsoft.sqlserver.jdbc.SQLServerDriver";//串連到資料庫 jdbc:資料庫名:地址:連接埠號碼;DatabaseName=資料庫名String url="jdbc:sqlserver://127.0.0.1:1433;DatabaseName=kbjSystemdb";String name="kbjlxx";String password="kbj123456"; Connection dbconn = null;try{Class.forName(driverName);dbconn=DriverManager.getConnection(url,name,password);//System.out.println("123");}catch(Exception ex){ex.printStackTrace();}return dbconn; }

測試連接

 public static void main(String[] args) {ConnectionDB c=new ConnectionDB();  Connection con=null;  Statement stmt=null;         ResultSet rs=null;         String sql="select userid,userName,password,addtime from login_temp";         con=c.conn();            try{                 stmt=con.createStatement();rs=stmt.executeQuery(sql);         while(rs.next())        {        System.out.print(rs.getString("userid")+"\t"                 +rs.getString("userName")+"\t"                 +rs.getString("password")+"\t"                 +rs.getString("addtime")+"\n");        }        }        catch(Exception ex)        {        ex.printStackTrace();        }        finally        {         try {con.close();} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}} } 

輸出結果!!

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.