快上网专注成都网站设计 成都网站制作 成都网站建设
成都网站建设公司服务热线:028-86922220

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

java的cs代码 java csharp

java CS 程序

这个是用配置文件连接数据库的例子,原理和xml一样,需要你解析文件。供你参考:

成都创新互联长期为成百上千家客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为麻江企业提供专业的成都做网站、网站制作、成都外贸网站建设麻江网站改版等技术服务。拥有10余年丰富建站经验和众多成功案例,为您定制开发。

db.properties文件内容(以oracle为例 )

# 驱 动:

driver = oracle.jdbc.OracleDriver

# 地 址:

url = jdbc:oracle:thin:@172.16.0.212:1521:orcl

# 用 户 名:

user = 1234

# 密 码:

password = 1234

# 初始连接数:

initialSize=10

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

代码:

public class DBUtils {

private static String driver =null;

private static String url = null;

private static String user = null;

private static String password = null;

private static BasicDataSource ds;

static{

//读取程序外的.properties 文件

//需要.properties文件的包路径

Properties props = new Properties();

try {

String path ="utils/db.properties";//路径根据你自己的实际情况

props.load(DBUtils.class.getClassLoader().getResourceAsStream(path));

//properties对象.getProperty("字符串")

driver=props.getProperty("driver");

url=props.getProperty("url");

user=props.getProperty("user");

password=props.getProperty("password");

ds = new BasicDataSource();

ds.setDriverClassName(driver);

ds.setUrl(url);

ds.setUsername(user);

ds.setPassword(password);

ds.setInitialSize(Integer.parseInt(props.getProperty("initialSize")));

Class.forName(driver);

} catch (Exception e) {

e.printStackTrace();

}

}

public static Connection getConnection()

throws SQLException {

Connection conn = null;

if(ds!=null)conn=ds.getConnection();

return conn;

}

public static void closeConnection(Connection conn) throws Exception {

if(conn!=null)conn.close();

}

public static void main(String[] args) throws SQLException {

DBUtils db=new DBUtils();

db.getConnection();

}

}

实现界面登陆,退出功能的java代码怎么写?

CS结构系统的退出如下:public void init() {

this.setTitle("用户登录界面");

this.add(createCenterPane());

this.setDefaultCloseOperation(this.DO_NOTHING_ON_CLOSE);

this.setSize(new Dimension(450, 335));

this.setLocationRelativeTo(null);

// this.setVisible(true);

this.addWindowListener(new WindowAdapter() {

public void windowClosing(WindowEvent e) {

int choose = JOptionPane.showConfirmDialog(null, "是否要退出登录界面?",

"系统提示:", JOptionPane.YES_NO_OPTION);

if (choose == JOptionPane.YES_OPTION) {

System.exit(1);

}

}

});

}其中this为JFrame对象。BS结构的退出直接用windows.close()方法就行了!

JAVA用nio写CS程序,服务器端接收到的信息不完整,求助!SocketChannel,Bytebuffer

while(true){

buff.clear();

int len = sc.read(buff);

if(len ==-1){ break;}

buff.flip();

content += charset.decode(buff);

}


当前题目:java的cs代码 java csharp
转载来于:http://6mz.cn/article/dojsdgj.html

其他资讯