The Artima Developer Community
Sponsored Link

Java Answers Forum
JSP - Bean - SQL

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Achimsen

Posts: 1
Nickname: speedy
Registered: Aug, 2003

JSP - Bean - SQL Posted: Aug 14, 2003 1:32 PM
Reply to this message Reply
Advertisement
Hi,

I've got some problems with my programm
I have a HTML-page with some input-types which I want to save by a .jsp-page in a Bean. Another Bean takes the input and save it to a sql-database. Thats how it should work, but it doesn't...

My .jsp file looks like this:

******************************
<%@ page language= "java"%>
<%@ page contentType="text/html" %>
<%@ page import="app.jdbcquery" %>

<jsp:useBean id="info3"class="app.company.MainContactAddressBean" />
<jsp:setProperty name="info3" property="lastName" />
<%
jdbcquery jdbc = new jdbcquery();
jdbc.connect() ;
%>
</jsp:useBean>
******************************

The name of the input-type in the HTML-File is "lastName".

The "Save" Bean looks like this:

******************************
package app.company;

import java.beans.*;
import java.io.*;
import java.util.*;

public class MainContactAddressBean implements java.io.Serializable {

private String lastName;

public void setLastName(String lastName) {
this.lastName = lastName;
}

public String getLastName() {
return lastName;
}
}
*****************************

and the jdbcquery looks like this

*****************************
package app;

import app.company.*;
import java.sql.*;
import java.net.URL;

public class jdbcquery extends MainContactAddressBean{

public void connect() {

MainContactAddressBean ln = new MainContactAddressBean();

try
{
Class.forName
("com.microsoft.jdbc.sqlserver.SQLServerDriver");

Connection connection =
DriverManager.getConnection
("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=Lo gin;SelectMethod=cursor", "username", "password");

Statement statement = connection.createStatement();
statement.executeUpdate("INSERT INTO MainContact VALUES
('" + ln.getLastName() +"')");

statement.close();
connection.close();
}
catch(java.lang.ClassNotFoundException e)
{
System.out.println
("JDBC-ODBC-Treiber nicht gefunden");
} catch(java.sql.SQLException e)
{
System.out.println
("Fehler beim Abfragen der Datenbank");
}
}
}

The Problem is, that when I type in data in the input type of the HTML-page the jdbcquery writes only "null" in the database. But when I put a <jsp:getProperty ... > in the HTML-page, he shows me the correct word which I have entered before.
When I set the "lastName" variable in the MainContactAddressBean to a value like "test" and change the connect() Method of the jdbcquery to a main-method and start the jdbcquery, it writes "test" to the database...
Unfortunately that is not the correct way I want this application to run... :) Have somebody an idea? Thanks

Topic: Dealing with Float Previous Topic   Next Topic Topic: problems compiling with dependencies

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use