Skip to Content
author's profile photo Former Member
Former Member

Database connection to MS SQL 2005 (URGENT Help Needed)

Hi all,

Does anyone know how to connect my adobe form to MS SQL 2005?

I have this code:

-


try {

InitialContext initialContext = new InitialContext ();

DataSource dataSource = (DataSource) initialContext.lookup ("jdbc/MyAlias");

java.sql.Connection connection = dataSource.getConnection ();

} catch (SQLException e) {

// handle exception

} catch (NamingException e) {

// handle exception

}

-


Other than these, what else do i need to do inorder to get my database connection up?

-


-


And after my database connection is up, how do i test to check if my database connection is up or not?

How do i extract the information from the database and put them onto the textfields/dropdownlists on my form?

Thanks In Advance

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jan 24, 2008 at 12:49 PM

    Hi Lim,

    You can use the below code for making a database connection and populating the value nodes.

    I have created a view called 'ABC' which has a context with VN called 'FillData' which has VA 'Name', 'Age' & 'Address'.

    //Code for database connection.

    InitialContext ctx = new InitialContext();

    DataSource ds = (DataSource)ctx.lookup("jdbc/AliasName");

    Connection conn = ds.getConnection();

    Statement st = null;

    ResultSet rs = null;

    IPrivateABCView.IFillDataElement dataEle = null;

    st = conn.createStatement();

    //Execute the appropriate SQL query

    rs = st.executeQuery("SELECT NAME,AGE,ADDRESS WHERE SEX='M' ");

    while(rs.next())

    {

    //Code that will populate your VN based on the data obtained in the ResultSet.

    dataEle = wdContext.createFillDataElement();

    dataEle.setName(rs.getString(1));

    dataEle.setAge(rs.getInt(2));

    dataEle.setAddress(rs.getString(3));

    wdContext.nodeFillData.addElement(dataEle);

    }

    Close the connections

    rs.close();

    st.close();

    conn.close();

    Add the appropriate Try--Catch blocks wherever necessary.

    A simple way to test the connection is to put Message Manager sts before and after the ds.getConnection() code.

    Hope this helps.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.