powered by simpleCommunicator - 2.0.61     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / Java [игнор отключен] [закрыт для гостей] / Подключение к БД MS SQL (пишу веб-приложение)
7 сообщений из 7, страница 1 из 1
Подключение к БД MS SQL (пишу веб-приложение)
    #38680500
RAMZEZ II
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Привет всем!
Средства: NetBeans 6.5 (Visual JSP!!!!!!!), GlassFish 3.0.1
Подскажите как подключиться к БД MS SQL при нажатии на кнопку.
В GlassFish создал пул и ресурс для подключения к БД Пингуется.
Теперь понимаю, что нужно в коде обратиться к этому ресурсу.
Проблема в том что использую визуальный конструктор JSP, а что писать в java-исходнике не знаю....
Нашел примеры для "невизуального" JSP, а для моего случая - нет...

Просьба сильно не пинать, если что .... Я тока учусь :)
...
Рейтинг: 0 / 0
Подключение к БД MS SQL (пишу веб-приложение)
    #38680551
RAMZEZ II
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
примерчик бы.....
...
Рейтинг: 0 / 0
Подключение к БД MS SQL (пишу веб-приложение)
    #38680557
Фотография Blazkowicz
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
...
Рейтинг: 0 / 0
Подключение к БД MS SQL (пишу веб-приложение)
    #38681396
RAMZEZ II
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
С подключением вроде разобрался, но почему то не появляется ошибка (хочу сделать обработку).
Вот код:
Код: java
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
130.
131.
132.
133.
134.
135.
136.
137.
138.
139.
140.
141.
142.
143.
144.
145.
146.
147.
148.
149.
150.
151.
152.
153.
154.
155.
156.
157.
158.
159.
160.
161.
162.
163.
164.
165.
166.
167.
168.
169.
170.
171.
172.
173.
174.
package wups;

import com.sun.data.provider.impl.ObjectDataProvider;
import com.sun.rave.web.ui.appbase.AbstractPageBean;
import com.sun.webui.jsf.component.Label;
import com.sun.webui.jsf.model.DefaultTableDataProvider;
import javax.faces.FacesException;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.Connection;
import javax.sql.DataSource;
import javax.naming.InitialContext;
import java.sql.SQLException;

public class pgMain extends AbstractPageBean {
    // <editor-fold defaultstate="collapsed" desc="Managed Component Definition">

    /**
     * <p>Automatically managed component initialization.  <strong>WARNING:</strong>
     * This method is automatically generated, so any user-specified code inserted
     * here is subject to being replaced.</p>
     */
    private void _init() throws Exception {
    }

    // </editor-fold>

    /**
     * <p>Construct a new Page bean instance.</p>
     */
    public pgMain() {
    }

    /**
     * <p>Callback method that is called whenever a page is navigated to,
     * either directly via a URL, or indirectly via page navigation.
     * Customize this method to acquire resources that will be needed
     * for event handlers and lifecycle methods, whether or not this
     * page is performing post back processing.</p>
     * 
     * <p>Note that, if the current request is a postback, the property
     * values of the components do <strong>not</strong> represent any
     * values submitted with this request.  Instead, they represent the
     * property values that were saved for this view when it was rendered.</p>
     */
    @Override
    public void init() {
        // Perform initializations inherited from our superclass
        super.init();
        // Perform application initialization that must complete
        // *before* managed components are initialized
        // TODO - add your own initialiation code here
        
        // <editor-fold defaultstate="collapsed" desc="Managed Component Initialization">
        // Initialize automatically managed components
        // *Note* - this logic should NOT be modified
        try {
            _init();
        } catch (Exception e) {
            log("Page1 Initialization Failure", e);
            throw e instanceof FacesException ? (FacesException) e: new FacesException(e);
        }
        
        // </editor-fold>
        // Perform application initialization that must complete
        // *after* managed components are initialized
        // TODO - add your own initialization code here
    }

    /**
     * <p>Callback method that is called after the component tree has been
     * restored, but before any event processing takes place.  This method
     * will <strong>only</strong> be called on a postback request that
     * is processing a form submit.  Customize this method to allocate
     * resources that will be required in your event handlers.</p>
     */
    @Override
    public void preprocess() {
    }

    /**
     * <p>Callback method that is called just before rendering takes place.
     * This method will <strong>only</strong> be called for the page that
     * will actually be rendered (and not, for example, on a page that
     * handled a postback and then navigated to a different page).  Customize
     * this method to allocate resources that will be required for rendering
     * this page.</p>
     */
    @Override
    public void prerender() {
    
    }

    /**
     * <p>Callback method that is called after rendering is completed for
     * this request, if <code>init()</code> was called (regardless of whether
     * or not this was the page that was actually rendered).  Customize this
     * method to release resources acquired in the <code>init()</code>,
     * <code>preprocess()</code>, or <code>prerender()</code> methods (or
     * acquired during execution of an event handler).</p>
     */
    @Override
    public void destroy() {
    }
    
    /**
     * <p>Return a reference to the scoped data bean.</p>
     *
     * @return reference to the scoped data bean
     */
    protected SessionBean1 getSessionBean1() {
        return (SessionBean1) getBean("SessionBean1");
    }

    /**
     * <p>Return a reference to the scoped data bean.</p>
     *
     * @return reference to the scoped data bean
     */
    protected RequestBean1 getRequestBean1() {
        return (RequestBean1) getBean("RequestBean1");
    }

    /**
     * <p>Return a reference to the scoped data bean.</p>
     *
     * @return reference to the scoped data bean
     */
    protected ApplicationBean1 getApplicationBean1() {
        return (ApplicationBean1) getBean("ApplicationBean1");
    }

    public class Connect{
        public void go() {
         try
         {
            InitialContext ctx = new InitialContext();
            //The JDBC Data source that we just created
            DataSource ds = (DataSource) ctx.lookup("jdbc/mssql");
            Connection conn = ds.getConnection();
            Statement stmt = conn.createStatement();

            if (conn == null)
            {
                //throw new SQLException("Ошибка подключения к БД!");
                error("Ошибка подключения к БД!");
            }
            String query = "SELECT * FROM dbo.t_Agent1";
            ResultSet rs = stmt.executeQuery(query);

         }
         catch (Exception e) {
            error(e.getMessage());
         }
        }
    }

    public String btnAccess_action() {
        // TODO: Process the button click action. Return value is a navigation
        // case name where null will return to the same page.
      try
      {
        Connect exec = new Connect();
        exec.go();
      }
      catch (Exception e) {
        error(e.getMessage());
      }
      finally {
       return "goMenu";
      }
    }

В SQL запросе есть ошибка, но она не появляется... :( 


...
Рейтинг: 0 / 0
Подключение к БД MS SQL (пишу веб-приложение)
    #38681843
Фотография Zukora
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
О ошибку мы должны угадать?
...
Рейтинг: 0 / 0
Подключение к БД MS SQL (пишу веб-приложение)
    #38681847
Фотография Blazkowicz
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
ZukoraО ошибку мы должны угадать?
Конечно. Она ведь "не появляется". Остаётся только угадывать.
...
Рейтинг: 0 / 0
Подключение к БД MS SQL (пишу веб-приложение)
    #38683404
RAMZEZ II
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Ошибка вот здесь: "SELECT * FROM dbo.t_Agent1"
Но приложение не выдает ее, но пишет в лог гласфиша... :(
...
Рейтинг: 0 / 0
7 сообщений из 7, страница 1 из 1
Форумы / Java [игнор отключен] [закрыт для гостей] / Подключение к БД MS SQL (пишу веб-приложение)
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]