java开发相关资料

来源:互联网 发布:淘宝cpu置换可靠吗 编辑:程序博客网 时间:2024/05/16 17:15

测试连接数据库 sql server 2008 R2

开发环境是 Eclipse

这个是纯Java驱动连接数据库的方式,需要下载 jdbc的驱动程序:sqljdbc4.jar  下载址址:http://good.gd/1963755.htm

Eclipse中的项目引用jar方法为:选中左侧的项目(如 test1),右键--> Properties --> Java Build Path--> Libraries --> Add External Jars -->选中刚才下载的 .jar 文件--> OK即可

---------------------------------------------------------------------------------------------

test1.java

[java] view plain copy
  1. //import javax.swing.JOptionPane;  
  2. public class test11 {  
  3.     public static void main(String[] args) {  
  4.             DBHelper help=new DBHelper();  
  5.             if(help.TestConn())  
  6.                 System.out.println("连接成功1");  
  7.             else  
  8.                 System.out.println("连接失败1");  
  9.               
  10.             //JOptionPane.showMessageDialog(null, "hello world");  
  11.     }  
  12. }  

DBHelper.java

[java] view plain copy
  1. import java.sql.*;  
  2. import com.microsoft.sqlserver.jdbc.*;  
  3.   
  4. public class DBHelper {  
  5.     Connection dbConn = null;  
  6.     private Connection GetConn(String sUser,String sPwd) {  
  7.         try {  
  8.             String sDriverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver";  
  9.             //String sDBUrl = "jdbc:sqlserver://192.168.0.74;databaseName=wakeup";  
  10.             String sDBUrl = "jdbc:sqlserver://192.168.2.28\\JONSE;databaseName=wakeup";  
  11.               
  12.             Class.forName(sDriverName);  
  13.             dbConn = DriverManager.getConnection(sDBUrl, sUser, sPwd);  
  14.         } catch (Exception ex) {  
  15.             //ex.printStackTrace();  
  16.             System.out.println(ex.getMessage());  
  17.         }  
  18.         return dbConn;  
  19.     }  
  20.       
  21.     public boolean TestConn()  
  22.     {  
  23.         if(GetConn("sa","***")==null)  
  24.             return false;  
  25.    
  26.         dbConn=null;  
  27.         return true;  
  28.     }  
  29.       
  30. }  

执行结果为:

---------------------------------------------------------------------------------------------

java    http://wenku.baidu.com/view/f091272cb4daa58da0114ab0.html

javasqlserver2005 http://wenku.baidu.com/view/add31ec62cc58bd63186bdb8.html

 

怎么用纯java驱动方式连接SQL server 2008 R2   http://zhidao.baidu.com/question/199399735.html

 Microsoft SQL Server JDBC Driver 3.0            

http://www.microsoft.com/downloads/zh-cn/details.aspx?FamilyID=a737000d-68d0-4531-b65d-da0f2a735707&displayLang=zh-cn

 JDBC连接SqlServer2008图解:直连(纯JAVA方式)       

http://blog.csdn.net/zhouhuan965/article/details/6258035

 sqljdbc2008.jar驱动    http://download.csdn.net/download/sksbbs/3460315

Java操作SQLite数据库   http://www.cxybl.com/html/bcyy/java/201110287250.html

使用纯Java JDBC驱动 程序实现数据库的连接出现错误  http://zhidao.baidu.com/question/356905375.html

如何用JAVA连接SQLite数据库?  http://zhidao.baidu.com/question/206230567.html?an=0&si=9

MSDN: Sql server jdbc 纯java驱动: 使用 JDBC 驱动程序  http://msdn.microsoft.com/zh-cn/library/ms378526.aspx 

eclipse添加classpath变量    http://blog.sina.com.cn/s/blog_3fe0f6250100amoh.html

通过端口 1433 连接到主机 localhost 的 TCP/IP 连接失败。错误:“Connecti...  http://apps.hi.baidu.com/share/detail/43639042

 用于JDBC操作数据库的公共类    http://vipbooks.iteye.com/blog/607207

java-sql数据库连接公共类文件     http://www.ineeke.com/archives/58/

 

Eclipse如何设置字体大小 : windows -> preference -> general -> apperance -> colors and fonts -> basic -> text font  双击它

默认字体为:Courier New 10

 

Eclipse 自动缩进快捷键: 全选代码,然后 Ctrl + Shift + F

0 0
原创粉丝点击