ÓÃÅäÖÃÎļþÁ¬½ÓÊý¾Ý¿â1.EclipseÖУ¬ÔÚsrcĿ¼Ï½¨Á¢db.propertiesÎļþ£¬ÔÚÀïÃæÅäÖÃÊý¾Ý¿âÁ¬½ÓËùÐèµÄDriver,url,user,possword£¬×¢ÒâµÈºÅ×óÓÒ²»ÄÜ¿Õ¸ñÈ磺driver=com.microsoft.sqlserver.jdbc.SQLServerDriverurl=jdbc:sqlserver://localhost:1433;databaseName=restrantuser=sapassword=1102.дһ¸öÊý¾Ý¿âÁ¬½ÓÀàimportjava.io.IOException;importjava.sql.*;importjava.util.Properties;publicConnectiongetCon(){Connectioncon=null;Propertiesproperties=newProperties();try{properties.load(this.getClass().getResourceAsStream(/db.properties));Stringdriver=properties.getProperty(driver);Stringurl=properties.getProperty(url);Stringuser=properties.getProperty(user);Stringpassword=properties.getProperty(password);try{Class.forName(driver);con=DriverManager.getConnection(url,user,password);}catch(ClassNotFoundExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}catch(SQLExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}}catch(IOExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}returncon;}