Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

JSP and Sybase Connection

  • 25-03-2003 12:27PM
    #1
    Registered Users, Registered Users 2 Posts: 822 ✭✭✭


    Hey guys and girls, I just have a quick question for you all:

    I've tried using classes and Now Im trying to just implement my JSP Site in jsp only. Here is my connection code:

    [PHP]
    <HTML>
    <HEAD><TITLE> Listing the Content of a Database</TITLE></HEAD>
    <BODY>
    <P> Content of the Product database:
    <TABLE BORDER=1 CELLPADDING=0 CELLSPACING=0>
    <TR><TD> Product Name </TD>
    <TD> Class </TD>
    <TD> Sub Class </TD>
    </TR>

    <% String strDBUser = "*****";
    String strDBPwd = "******";

    Class.forName("com.sybase.jdbc2.jdbc.SybDriver");
    //java.sql.Connection connection = java.sql.DriverManager.getConnection(strDBUrl, props);
    java.sql.Connection connection = java.sql.DriverManager.getConnection("jdbc:sybase:Tds:BLAH:5000/BLAH");
    java.sql.Statement statement = connection.createStatement();
    java.sql.ResultSet columns = statement.executeQuery("SELECT * FROM euro_products");

    while(columns.next()){

    String prod_name = columns.getString("prod_name");
    String prod_class = columns.getString("prod_classification");
    String prod_sub_class = columns.getString("prod_sub_classification");
    %>
    <TR><TD> <%=prod_name%> </TD>
    <TD> <%=prod_class%> </TD>
    <TD> <%=prod_sub_class%> </TD>
    </TR>

    <% } %>
    </TABLE>
    </BODY>
    </HTML>
    [/PHP]

    I get the Following Error:

    "org.apache.jasper.JasperException: JZ004: User name property missing in DriverManager.getConnection(..., Properties)."

    I have tried to implement the following code.....

    [PHP]
    String strDBUser = "";
    String strDBPwd = "";
    String strDBUrl = "jdbc:sybase:Tds:BLAH:5000/BLAH";// database URL

    ......
    Properties props = new Properties();
    props.put("user", strDBUser);
    props.put("password", strDBPwd);
    [/PHP]

    ....... into

    [PHP]
    java.sql.Connection connection = java.sql.DriverManager.getConnection(strDBUrl, props);
    [/PHP]

    Can anyone see where I would put "Properties ". I've tried various combinations but cant get it. Can anyone help?

    Cheers in advance

    :)


Comments

  • Registered Users, Registered Users 2 Posts: 822 ✭✭✭Mutz


    No Matter!

    I found it! For the benefit of anyone else who may be in the same JSP/Sybase dilema soon:

    [PHP]
    <%@ page import= "java.sql.*" %>
    <%Class.forName("com.sybase.jdbc2.jdbc.SybDriver");%>
    <HTML>
    <HEAD><TITLE> Listing the Content of a Database</TITLE></HEAD>
    <BODY>
    <P> Content of the Product database:
    <TABLE BORDER=1 CELLPADDING=0 CELLSPACING=0>
    <TR><TD> Product Name </TD>
    <TD> Class </TD>
    <TD> Sub Class </TD>
    </TR>

    <%
    String theDatabase = "jdbc:sybase:Tds:BLAH:5000/BLAH";
    Connection connection = java.sql.DriverManager.getConnection(theDatabase,"Username","Password");
    Statement statement = connection.createStatement();
    ResultSet columns = statement.executeQuery("SELECT * FROM euro_products");

    while(columns.next()){

    String prod_name = columns.getString("prod_name");
    String prod_class = columns.getString("prod_classification");
    String prod_sub_class = columns.getString("prod_sub_classification");
    %>
    <TR><TD> <%=prod_name%> </TD>
    <TD> <%=prod_class%> </TD>
    <TD> <%=prod_sub_class%> </TD>
    </TR>

    <% } %>
    </TABLE>
    </BODY>
    </HTML>
    [/PHP]


Advertisement