You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Sławek Tuleja <tu...@wp.pl> on 2005/08/10 20:28:10 UTC
login and password problem
Hello
1.) I have this in struts-config.xml:
-----------------------------------------------------------------------
<data-sources>
<data-source
type="org.apache.commons.dbcp.BasicDataSource" >
<set-property property="driverClassName"
value="com.microsoft.jdbc.sqlserver.SQLServerDriver" />
<set-property property="url"
value="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=legra"
/>
<set-property property="username"
value="myUserName" />
<set-property property="password"
value="myPassword" />
</data-source>
</data-sources>
------------------------------------------------------------------------
2.) but I want to give username and password in java file
------------------------------------------------------------------------
public class LoginJDBC {
public static String getStatusRoli(String UserName, String Password,
DataSource dataSource)
throws Exception {
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
String status = null;
try {
//------------------------------------
//HOW TO INSERT THIS NEW CODE IN HERE?
//------------------------------------
conn = dataSource.getConnection();
stmt = conn.createStatement();
rs =
stmt.executeQuery("SELECT status_roli FROM
legra_uzytkownicy WHERE "
+ "UserName = '" + UserName + "' AND " + "Password =
'" + Password + "'"
+ " AND usuniete='nie' AND status_konta='aktywne'");
if ( rs.next() ) {
status = rs.getString("status_roli");
} else {
throw new Exception(UserName + " nie znaleziono!");
}
} finally {
if ( rs != null ) {rs.close();}
if ( stmt != null ) {stmt.close();}
if ( conn != null ) {conn.close();}
}
return status;
}
}
------------------------------------------------------------------------------
3.) How to change struts-config.xml
4.) SUMMARY :
i do not want to link my program with database via struts-config.xml
i want to link my program with database when i put in the login and the
password
5.) Could you help me?
--
------------------------------------
Sławek Tuleja
ul. Spółdzielców 12/81, Kraków 30-682
tel: (012) 655 50 57
www.tusla.pl
------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: login and password problem
Posted by Swapnil Patil <sw...@gmail.com>.
Hi Sławek,
I am new in Strurts framwork. If I am going wrong please correct me.
As you said -: i do not want to link my program with database via
struts-config.xml
Don't specify any data source in your struts-config.xml
Create your own static class to create a connection with database. and use
this class in your Sturts Action classes to make connection with database.
In stort
Sturts Action ---> Bussiness Object -----> Database
class (static class making
connection with DB)
I hope this will help.
Thanks & Regards
Swapnil
On 8/10/05, Sławek Tuleja <tu...@wp.pl> wrote:
>
> Hello
>
> 1.) I have this in struts-config.xml:
>
> -----------------------------------------------------------------------
> <data-sources>
> <data-source
> type="org.apache.commons.dbcp.BasicDataSource" >
> <set-property property="driverClassName"
> value="com.microsoft.jdbc.sqlserver.SQLServerDriver" />
> <set-property property="url"
> value="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=legra"
> />
> <set-property property="username"
> value="myUserName" />
> <set-property property="password"
> value="myPassword" />
> </data-source>
> </data-sources>
> ------------------------------------------------------------------------
>
> 2.) but I want to give username and password in java file
>
> ------------------------------------------------------------------------
> public class LoginJDBC {
>
> public static String getStatusRoli(String UserName, String Password,
> DataSource dataSource)
> throws Exception {
>
> Connection conn = null;
> Statement stmt = null;
> ResultSet rs = null;
> String status = null;
> try {
>
> //------------------------------------
> //HOW TO INSERT THIS NEW CODE IN HERE?
> //------------------------------------
>
> conn = dataSource.getConnection();
> stmt = conn.createStatement();
> rs =
> stmt.executeQuery("SELECT status_roli FROM
> legra_uzytkownicy WHERE "
> + "UserName = '" + UserName + "' AND " + "Password =
> '" + Password + "'"
> + " AND usuniete='nie' AND status_konta='aktywne'");
>
> if ( rs.next() ) {
> status = rs.getString("status_roli");
> } else {
> throw new Exception(UserName + " nie znaleziono!");
> }
> } finally {
> if ( rs != null ) {rs.close();}
> if ( stmt != null ) {stmt.close();}
> if ( conn != null ) {conn.close();}
> }
> return status;
> }
> }
>
> ------------------------------------------------------------------------------
>
> 3.) How to change struts-config.xml
>
> 4.) SUMMARY :
>
> i do not want to link my program with database via struts-config.xml
> i want to link my program with database when i put in the login and the
> password
>
>
> 5.) Could you help me?
>
>
>
>
>
>
>
>
>
>
> --
> ------------------------------------
> Sławek Tuleja
> ul. Spółdzielców 12/81, Kraków 30-682
> tel: (012) 655 50 57
> www.tusla.pl <http://www.tusla.pl>
> ------------------------------------
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>