Each SQL Anywhere database server can have one or more databases loaded at a time. If the URL you supply when connecting via jConnect specifies a server, but does not specify a database, then the connection attempt is made to the default database on the server.
You can specify a particular database by providing an extended form of the URL in one of the following ways.
jdbc:sybase:Tds:host:port?ServiceName=database |
The question mark followed by a series of assignments is a standard way of providing arguments to a URL. The case of ServiceName is not significant, and there must be no spaces around the = sign. The database parameter is the database name, not the server name. The database name must not include the path or file suffix. For example:
Connection con = DriverManager.getConnection( "jdbc:sybase:Tds:localhost:2638?ServiceName=demo", "DBA", "sql"); |
A workaround exists for passing additional connection parameters to the server.
This technique allows you to provide additional connection parameters such as the database name, or a database file, using the RemotePWD field. You set RemotePWD as a Properties field using the put method.
The following code illustrates how to use the field.
import java.util.Properties; . . . DriverManager.registerDriver( (Driver) Class.forName( "com.sybase.jdbc3.jdbc.SybDriver").newInstance() ); Properties props = new Properties(); props.put( "User", "DBA" ); props.put( "Password", "sql" ); props.put( "RemotePWD", ",DatabaseFile=mydb.db" ); Connection con = DriverManager.getConnection( "jdbc:sybase:Tds:localhost:2638", props ); |
As shown in the example, a comma must precede the DatabaseFile connection parameter. Using the DatabaseFile parameter, you can start a database on a server using jConnect. By default, the database is started with autostop=YES. If you specify utility_db with a DatabaseFile (DBF) or DatabaseName (DBN) connection parameter (for example, DBN=utility_db), then the utility database is started automatically.
For more information about the utility database, see Using the utility database.
Send feedback about this page via email or DocCommentXchange | Copyright © 2008, iAnywhere Solutions, Inc. - SQL Anywhere 11.0.0 |