Home > Archive > SQL Anywhere database > July 2005 > Re: Autostart the Sybase database engine (dbeng9.exe or rteng9.exe)









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: Autostart the Sybase database engine (dbeng9.exe or rteng9.exe)
Greg Fenton

2005-07-09, 3:23 am

Melody Pedzisai wrote:
> I am looking for a way to startup the database engine from a Java program
> that is using JDBC to connect to a Sybase 9 database. In other words I need
> to be able to get my users to open a .db file and fire the database engine
> automatically withou having to call a Java Runtime command.
>


Here is (quick and dirty) code that automatically starts the asademo.db
database using the iAnywhere JDBC driver.

//--------- Start of TestIasJdbc.java ----------------------------
import java.sql.*;

public class TestIasJdbc {

public static String DB_DIR = "c:/program files/sqlanywhere 9";

public static void main(String args[]) {
try {
String driver, url;
Connection conn;
driver="ianywhere.ml.jdbcodbc.IDriver";
url = " jdbc:odbc:driver=Ada
ptive Server Anywhere 9.0"
+ " ;uid=DBA;pwd=SQL;dbf
=" + DB_DIR
+ "/asademo.db";
Class.forName( driver );
conn = DriverManager.getConnection( url );
if ( conn != null ) {
System.out.println("connected");
System.exit(0);
} else {
System.out.println("connection failed!");
System.exit(10);
}
} catch (Exception ex) {
System.out.println( ex.getMessage() );
}
}
}
//--------- End of TestIasJdbc.java -------------------------------


Change the value of DB_DIR to a directory containing asademo.db.

The command to compile the code in a win32 shell is:

javac -classpath "%ASANY9%\java\jodbc.jar" TestIasJdbc.java

The command to run the class is:

java -classpath ". ;%ASANY9%\java\jodbc
.jar" TestIasJdbc


Note that if you are having connectivity problems, you might add
"log=c:/asa_connect.txt" to the URL and after running this program take
a look at the contents of c:/asa_connect.txt for connection debugging
from the client library.

Hope this helps,
greg.fenton
--
Greg Fenton
Consultant, Solution Services, iAnywhere Solutions
--------
Visit the iAnywhere Solutions Developer Community
Whitepapers, TechDocs, Downloads
http://www.ianywhere.com/developer/
Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com