<?xml version="1.0" encoding="UTF-8"?>
<!-- $Id: mysql-ds.xml,v 1.1.2.1 2003/12/12 19:19:56 starksm Exp $ -->
<!-- Datasource config for MySQL using 3.0.9 available from:
http://www.mysql.com/downloads/api-jdbc-stable.html
-->
<datasources>
<local-tx-datasource>
<jndi-name>MySqlServer</jndi-name>
<connection-url>jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=LEDDATA</connection-url>
<driver-class>com.microsoft.jdbc.sqlserver.SQLServerDriver</driver-class>
<parameter>
<name>maxActive</name>
<value>20</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>10</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>-1</value>
</parameter>
<user-name>sa</user-name>
<password>guoyin</password>
<min-pool-size>20</min-pool-size>
<max-pool-size>200</max-pool-size>
</local-tx-datasource>
</datasources>
//java中写入
package com.prg.safety.model.business.LEDScreenSet.datasource;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import javax.naming.InitialContext;
import javax.sql.DataSource;
public class DataSourceManager {
public DataSourceManager(){};
private InitialContext ctx=null;
private Connection conn=null;
private DataSource ds=null;
private Statement stmt=null;
//datasource
public boolean DataSourceConnection(String path){
try {
ctx = new InitialContext();
ds = (DataSource)ctx.lookup("java:/MySqlServer");//这里要和mySqlServer-ds.xml中对应
if(null!=ds){
//得到连接
conn = ds.getConnection();
if(null!=conn){
stmt= conn.createStatement();
String sql = "update PICNAME SET FILENAME='" + path + "'";
int i = stmt.executeUpdate(sql);
if(i>0){
return true;
}
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally{
if(stmt!=null)
stmt=null;
if(conn!=null)
conn=null;
}
return false;
}
}