Programmatic Configuration

The purpose of programmatic configuration is to define a data source, then deploy it under a logical name to a name server.

If the server needs to be reconfigured (for example, moved to another machine, port, and so on), the administrator runs this configuration utility (outlined as follows) and reassigns the logical name to the new data source configuration. This phase is typically done by the person who performs database system administration or application integration for their company. As a result, the client code does not change, since it knows only the logical name.

import javax.sql.*;
import com.sybase.jdbcx.*;
.....
// create a SybDataSource, and configure it
SybDataSource ds = new com.sybase.jdbc4.jdbc.SybDataSource();
ds.setUser("my_username");
ds.setPassword("my_password");
ds.setDatabaseName("my_favorite_db");
ds.setServerName("db_machine");
ds.setPortNumber(4000);
ds.setDescription("This DataSource represents the Adaptive Server
    Enterprise server running on db_machine at port 2638.  The default
    username and password have been set to 'me' and 'mine' respectively.  
    Upon connection, the user will access the my_favorite_db database on 
    this server.");
Properties props = newProperties()
props.put("REPEAT_READ","false");
props.put("REQUEST_HA_SESSION","true");
ds.setConnectionProperties(props);
// store the DataSource object. Typically this is
// done by setting JNDI properties specific to the
// type of JNDI service provider you are using.
// Then, initialize the context and bind the object.
Context ctx = new InitialContext();
ctx.bind("java:comp/env/jdbc/myASE", ds);

Once you set up your DataSource, decide where and how you want to store the information. To assist you, SybDataSource is both java.io.Serializable and javax.naming.Referenceable, but it is still up to the administrator to determine how the data is stored, depending on what service provider you are using for JNDI.