master
X’moe 9 years ago
parent e1ec00fba5
commit 8d24212be6

Binary file not shown.

@ -9,9 +9,8 @@ import javax.naming.NamingException;
public class ContextManager
{
final static private String url = "t3://localhost:7001";
final static private String user = "xmoe";
final static private String password = "cbiloli7";
final static private String user = null;
final static private String password = null;
static private Context ctx = null;

@ -13,9 +13,10 @@ import javax.sql.DataSource;
public class DataBaseManager
{
private static DataBaseManager instance;
private DataSource dataSource1;
private DataSource dataSource2;
private static DataBaseManager instance = null;
private DataSource dataSource1 = null;
private DataSource dataSource2 = null;
private DataSource dataSource3 = null;
// private DataSource dataSource;
@ -33,6 +34,7 @@ public class DataBaseManager
{
dataSource1 = (DataSource) ctx.lookup("mysql1");
dataSource2 = (DataSource) ctx.lookup("mysql2");
dataSource3 = (DataSource) ctx.lookup("mysql3");
}
catch (NamingException e)
@ -72,6 +74,17 @@ public class DataBaseManager
}
}
public final Connection getConnection3()
{
try
{
return dataSource3.getConnection();
}
catch (SQLException e)
{
throw new RuntimeException("无法从数据源获取连接 database3", e);
}
}
public void TestConn1() throws SQLException
{

@ -25,6 +25,7 @@ public class JTATransaction
catch (NamingException e)
{
// TODO Auto-generated catch block
System.err.println("Cannot find UserTransaction in JNDI");
e.printStackTrace();
}
return utx;

@ -39,37 +39,6 @@ public class WebMain extends HttpServlet
out.close();
/*
Context ctx = null;
try
{
ctx = new InitialContext();
}
catch (NamingException e)
{
// TODO Auto-generated catch block
System.err.println("Failed to create context!");
e.printStackTrace();
}
try
{
dataSource1 = (DataSource) ctx.lookup("java:comp/env/jndi/mysql1");
dataSource2 = (DataSource) ctx.lookup("java:comp/env/jndi/mysql2");
}
catch (NamingException e)
{
// TODO Auto-generated catch block
System.err.println("Failed to find context");
e.printStackTrace();
return;
}
System.out.print("Ok, Context and jndi found!");
*/
try {
JTAConnManager.getInstance().TestConn1();
} catch (SQLException e) {
@ -77,7 +46,6 @@ public class WebMain extends HttpServlet
System.err.println("%%% Error Get Datebase Connection! %%%");
e.printStackTrace();
}
}
protected void doPost(HttpServletRequest req, HttpServletResponse res)

Loading…
Cancel
Save