Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Server \ Eclipse, Tomcat configuration JNDI connection Oracle data source example     - Linux system security check method (Linux)

- Use MySQL optimization of security to prevent misuse of aliases (Database)

- To install and deploy PHP environment under the CentOS (Server)

- How to turn Java String into Date (Programming)

- Linux iptables: Composition Rules (Linux)

- Java gets the current system time System.currentTimeMillis () (Programming)

- Haproxy multi-domain certificate HTTPS (Server)

- Use PDFBox parse PDF file (Linux)

- Ubuntu 14.04 after the restart the default maximum screen brightness solutions (Linux)

- Oracle Migration partition table (Database)

- C # how to generate a folder or file automatically rename (Programming)

- MySQL can not write the data keyword conflicts (Database)

- CentOS6.x and Windows XP and Windows Server 2003 Open IPv6 related matters (Linux)

- Java recognize simple codes (Programming)

- LVM mirrored logical volume to achieve (Linux)

- Installation under Linux Mint system guidelines for Gtk (Linux)

- CentOS7 install MySQL 5.5 (Database)

- How to use the process on the desktop xkill end Linux (Linux)

- Mutt - an email client that sends messages through the terminal (Linux)

- SSH does not require a password to log on to a Linux server (Server)

 
         
  Eclipse, Tomcat configuration JNDI connection Oracle data source example
     
  Add Date : 2018-11-21      
         
         
         
  Recently changed to the new company, the first contact with JNDI connected database.

A start could not find how to find the address of the database where the configuration, followed by the code found in the spring dataSource initialization is passed through this class JndiObjectFactoryBean jndiName parameters, decisive Baidu JndiObjectFactoryBean know there JNDI obtained in this way dataSource.

As the project is distributed (uniform use Jboss), if you want to separate the deployment configuration Jboss port too much trouble, so would like to use tomcat instead. jboss configuration JNDI is relatively simple, do not speak here. eclipse will automatically create a tomcat service Servers to build a project, which contains the context.xml, server.xml and other configuration files, you need to be careful not to configure tomcat configuration profile tomcat directory, but you need to configure this profile.

Configuration is as follows:

First, in the Servers project following context.xml file when you add the following configuration information:
< Context>

< Resource name = "jdbc / test" auth = "Container"
type = "javax.sql.DataSource"
username = "sean"
password = "sean"
driverClassName = "Oracle.jdbc.driver.OracleDriver"
url = "jdbc: oracle: thin: @localhost: 1521: orcl"
maxActive = "100"
maxIdle = "30"
maxWait = "10000" />

< / Context>

Second, in the following web.xml Configuration Servers project

< Resource-ref>
    < Description> OracleDataSource < / description>

    < Res-ref-name> jdbc / test < / res-ref-name>
    < Res-type> javax.sql.DataSource < / res-type>
    < Res-auth> Container < / res-auth>
< / Resource-ref>

Three, spring get dataSource

< ! - Report data access to modify the way jndi ->
< Bean id = "dataSource" name = "default_ds" class = "org.springframework.jndi.JndiObjectFactoryBean">
< Property name = "jndiName" value = "jdbc / test" />
< Property name = "resourceRef" value = "true" />
< / Bean>

 

Fourth, using a data source database
private Connection getConnection () throws NamingException {
Connection conn = null;
String jndi = "jdbc / test";
Context initContext = new InitialContext ();
  Context envContext = (Context) initContext.lookup ( "java: / comp / env");
  DataSource ds = (DataSource) envContext.lookup (jndi);
  if (ds! = null) {
  try {
conn = ds.getConnection ();
} Catch (SQLException e) {
e.printStackTrace ();
}
  }

  return conn;
}


public List < String> selectById (int id) throws InstantiationException, IllegalAccessException {
Connection con = null;
try {
con = getConnection ();
} Catch (NamingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace ();
}
List < String> list = new ArrayList < String> ();
String sql = "select * from myusers where id =?";
try {
PreparedStatement pstmt = con.prepareStatement (sql);
pstmt.setInt (1, id);
ResultSet rs = pstmt.executeQuery ();
if (rs.next ()) {
list.add (rs.getString (1));
list.add (rs.getString (2));
list.add (rs.getString (3));
System.out.println (rs.getString (1));
System.out.println (rs.getString (2));
System.out.println (rs.getString (3));
}
} Catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace ();
}
return list;
}
     
         
         
         
  More:      
 
- Talk about the Linux folder permissions issue again (Linux)
- Fedora 20 users install the Mate 1.8 desktop (Linux)
- Several back door and log tool under Linux (Linux)
- Experts teach you how to identify the actual functional differences between the firewall (Linux)
- Compiling source code Nginx module installation subs_filter (Server)
- Linux partition command (Linux)
- MySQL multi-instance configuration (Database)
- CentOS 7 Add yum source (Linux)
- Java Foundation - Getting Start (Programming)
- Linux ps command (Linux)
- Install GAMIT / GLOBK 10.50 software under Ubuntu 14.04 (Linux)
- Ubuntu How to install screen recording tool Simple Screen Recorder 0.3.1 (Linux)
- Analysis of Java keyword final (Programming)
- Ubuntu 12.04 installation instructions under GAMIT10.40 (Linux)
- Free compiler install MySQL-5.6.14 (Database)
- Puppet subcommands Introduction (Server)
- Linux System Getting Started Learning: Join cron job in Linux (Linux)
- Linux set the maximum number of open files nofile and nr_open, file-max Description (Linux)
- C ++, overloading, cover, hide (Programming)
- Getting Started with Linux system to learn: How do I know which processes are running on the CPU core (Linux)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.