Start Syabse Central
Start Sybase Central, after the program is up and running, double click on its tray icon. You will see an image similar to the one shown below.
Get the port number which sybase central is using.
Establishing the connection
Once you have the correct JDBC driver installed, establishing a connection from your Java program to Sybase database is pretty easy.Before we compile the test.java file, open the file in your favorite text editor and edit the arguments of the openDatabase method and put your database name, port number, username and password.
Connection db = openDatabase("com.sybase.jdbc3.jdbc.SybDriver", "jdbc:sybase:Tds:localhost:2638?ServiceName=storage",
"Test", "Dummy");
I have a table named 'test_table' on which i am executing the 'select *' sql query. Change the test_table to an appropriate table name from your database. Make similar changes with 'insert into' sql query.
get_rs = get_stmt.executeQuery("select * from test_table ");
update_stmt.executeUpdate("insert into test_table values ( 'Success', 1 )");
update_stmt.executeUpdate("insert into test_table values ( 'Success', 1 )");
Just compile and run the test.java program.
javac test.java
java test
java test
Conclusion
If everything worked properly you will see the contents of the 'test_table' table. If it did not run properly, double check your classpath, connection string. Try to find the root cause of the problem by reading the error thrown by the java program.Page 1 2