给出一个JNDI用来查找dataSource的例子?
8.jndi用来查找datasource的例子:
import javax.naming.initialcontext;
import javax.naming.context;
import com.mysql.jdbc.jdbc2.optional.mysqlconnectionpooldatasource;
import java.util.properties;
import net.sourceforge.jtds.jdbcx.*;
public class classput {
public static void main(string a[]) {
try {
/* jtdsdatasource datasource=new jtdsdatasource();
datasource.setservername("localhost");
datasource.setdatabasename("northwind");
datasource.setuser("sa");
datasource.setpassword("1234");
*/
mysqlconnectionpooldatasource ds = new mysqlconnectionpooldatasource();
ds.seturl("jdbc:mysql://localhost:3306/test");
ds.setuser("root");
ds.setpassword("1234");
properties prop = new properties();
prop.setproperty(context.initial_context_factory,
"com.sun.jndi.fscontext.reffscontextfactory");
context ctx=new initialcontext(prop);
/*here the following statement writes a file .bindings under the f disk. because this project is under the f disk.*/
ctx.rebind("abc",ds);
} catch (exception e) {
e.printstacktrace();
}
}
}
上面的程序只是存入硬盘,想查找出来得用下面的程序:
import javax.naming.initialcontext;
import javax.naming.context;
import com.mysql.jdbc.jdbc2.optional.mysqlconnectionpooldatasource;
上一篇: linux子系统折腾记 (二)
下一篇: 脸和屁股