Skip to Content

Just for those who are going to start programming with Sybase ASE and JAVA, or those who want to test this great RDBMS.

Requirements:

Install a JAVA JDK.

You can use any IDE like Eclipse.

Install Sybase ASE, could be Developer Edition.

Create a project new JAVA Project then copy and paste the following code.

Code example:

package jdbc;
import java.sql.*;
import java.util.*;
public class Jdbc {
 public static void main(String[] args) {

  try{
      Class.forName("com.sybase.jdbc4.jdbc.SybDriver");
      } catch (ClassNotFoundException cnfe){
        System.out.println("Could not find the JDBC driver!");
        System.exit(1);
      }
  Connection conn = null;
  try {
      conn = DriverManager.getConnection("jdbc:sybase:Tds:**HOST**:**PORT**/**DATABASE**","**USER**","**PASSWORD**");
      System.out.println("Connection done");
   Statement stmt = conn.createStatement();
   ResultSet rs = stmt.executeQuery( "SELECT * FROM **DATABASE**");
   System.out.println("ID \t Store \t Fecha");
         while ( rs.next( ) ) {
           System.out.println( rs.getString("**COLUMN**")+"\t"+rs.getString("**COLUMN**")+"\t"+rs.getString("**COLUMN**") );
         }
       } catch (SQLException sqle) {
         System.out.println("Could not connect");
         System.exit(1);
        }
 }
}
To report this post you need to login first.

1 Comment

You must be Logged on to comment or reply to a post.

Leave a Reply