Inserting a Value from a table into an SMS message

Hi,
I have a page sending an sms message, but I want to include in the message a "UserName" from the table in the database.
The following code is what I have, and the "Phone" and "UserName" are coming from the same table.


<%@ page session="true" %>
<%@ page language="java" contentType="text/html" import="java.sql.*, java.util.*, java.lang.*, java.io.* " errorPage="errorpage.jsp" %>

<%@ page import="java.util.*" %>
<HTML>
<%
out.print("Administrator logged in: " + session.getValue("UserName")+ "<br>");
%>
                    </p>
                    <p>                
  <%
Statement     statement = null;
ResultSet     resultset = null;
ResultSetMetaData rsmd = null;
Connection     connection = null;

                Class.forName("org.gjt.mm.mysql.Driver").newInstance();
               connection = DriverManager.getConnection(
                  "jdbc:mysql://localhost/combcdte_project?user=&password=");    
statement = connection.createStatement();

String name  = "'" + request.getParameter("name") + "'";
System.out.println("user is : -->"+name); // to check if we are getting the user name correctly

ResultSet rs = statement.executeQuery("SELECT * FROM Member WHERE UserName="+name);
String user = "xxxxx";
String  password = "xxxxx";
String  api_id = "xxxxx";
String  baseurl ="http://api.clickatell.com";
String  text = "Hi, Thank you for participating "; // Part having trouble with - do I need + <%=rs.getString ("UserName")%> + // in this part or is it something different??

String  to = "Mobile";
if(rs.next())
{
out.println("found phone");
out.println("Mobile");
to =rs.getString("Mobile");
}
%>
<html>
<body>
<frame  src="http://api.clickatell.com/http/sendmsg?user=<%=user%>&password=<%=password%>&api_id=<%=api_id%>&to=<%=to%>&text=<%=text%>"></frame>
                    <p align="center">&nbsp;</p>
                    <p align="center">&nbsp;</p>
</body>
</html>
 <%
{
    connection.close();
}

%>  

This is fairly urgent so any help is welcome thanks
acslaterAsked:
Who is Participating?
 
bloodredsunCommented:
String  text = "Hi, " + name + " Thank you for participating ";

or even better
String  text = "" ;
String  to = "Mobile";
if(rs.next())
{
    text = "Hi "+ rs.getString ("UserName") +", Thank you for participating ";
    out.println("found phone");
   out.println("Mobile");
   to =rs.getString("Mobile");
}
0
 
bloodredsunCommented:
If it's the Username from the SQL statement below

ResultSet rs = statement.executeQuery("SELECT * FROM Member WHERE UserName="+name);

 you should be able to go

String  text = "Hi, Thank you for participating " + name;
0
 
acslaterAuthor Commented:
This is what im trying to use now ...

>>String  text = "Hi, " + name + " Thank you for participating

Is this the corrext syntax?
I tried

>>String  text = "Hi, + name + Thank you for participating

but just printed out :

Hi name  Thank You ...
0
 
acslaterAuthor Commented:
The bottom one worked a treat :)
Thanks
0
 
bloodredsunCommented:
Great!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.