Servlet doesn't write to mySQL DB, why???

I made a servlet that should write a string to a MySQL DB but it doesn't. I have coded the entire DB writing process before the servlet and it worked OUTSIDE a servlet, I mean, it writed to the DB when it was ran in a JAVA API apart from servlet. Now, the servlet is not writing it, please check my code to tell me what's wrong, thanks
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.BufferedReader;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.ParserConfigurationException;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.w3c.dom.*;
import org.apache.xml.serialize.*;
import java.net.URLDecoder;
import java.sql.*;
import org.xml.sax.InputSource;
import java.io.StringReader;
* This class is made as a servlet for receiving strings and saving
* them as DB records and XML files, it will save each sms in a different XML
* generating the automatic number of the SMS.
* <p>Bugs: (None untill now, please notify if you find one)
* @author (Helder Martins ([email protected]))
public class xmlwriter extends HttpServlet
//Public variables we will need
public String Stringid;
public String Stringpath;
public String st;
public int nid;
//Servlet service method, which permits listening of events
public void service(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
try {
//Initialization for reading XMLs
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
Document doc = docBuilder.parse (new File("C:/Program Files/Apache Software Foundation/Tomcat 5.0/webapps/XMLSender/conf.xml"));
//XML reading....
NodeList listaconf = doc.getElementsByTagName("conf");
for(int s=0; s<listaconf.getLength() ; s++)
Node nodosms = listaconf.item(s);
if(nodosms.getNodeType() == Node.ELEMENT_NODE)
Element elementoconf = (Element)nodosms;
//-------First Node (ID)
NodeList listaid = elementoconf.getElementsByTagName("id");
Element elementoid = (Element)listaid.item(0);
NodeList textidList = elementoid.getChildNodes();
Stringid = ((Node)textidList.item(0)).getNodeValue().trim();
//Incrementing the ID into the XML
st=Stringid;
nid = Integer.parseInt(st);
nid = nid + 1;
st = Integer.toString(nid);
((Node)textidList.item(0)).setNodeValue(st);
//Writing the changes to the XML...
OutputFormat format = new OutputFormat(doc);
FileWriter fw = new FileWriter("C:/Program Files/Apache Software Foundation/Tomcat 5.0/webapps/XMLSender/conf.xml");
XMLSerializer serial = new XMLSerializer(fw, format);
serial.asDOMSerializer();
serial.serialize(doc.getDocumentElement());
fw.close();
//System.out.println(Stringid);
//-------Second Node (Path for the messages)
NodeList listapath = elementoconf.getElementsByTagName("path");
Element elementopath = (Element)listapath.item(0);
NodeList textpathList = elementopath.getChildNodes();
Stringpath = ((Node)textpathList.item(0)).getNodeValue().trim();
//System.out.println(Stringpath);
//Catching errors for the SAX and XML parsing
catch (SAXParseException err)
System.out.println ("** Parsing error" + ", line " + err.getLineNumber () + ", uri " + err.getSystemId ());
System.out.println(" " + err.getMessage ());
catch (SAXException e)
Exception x = e.getException ();
((x == null) ? e : x).printStackTrace ();
catch (Throwable t)
t.printStackTrace ();
//Initialization for the servlet
ServletOutputStream salida = res.getOutputStream();
ServletInputStream entrada = req.getInputStream();
//Reading of the entering string
BufferedReader lector = new BufferedReader(new InputStreamReader (entrada));
res.setContentType("text/HTML");
try {
//Database handler
Class.forName("org.gjt.mm.mysql.Driver");
DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
InputSource inStream = new InputSource();
inStream.setCharacterStream(new StringReader(lector.readLine()));
Document doc1 = builder.parse(inStream);
NodeList listasms = doc1.getElementsByTagName("sms");
for(int s=0; s<listasms.getLength() ; s++)
Connection Conn = DriverManager.getConnection ("jdbc:mysql://localhost:3306/smsdb","root", "");
Node nodosms = listasms.item(s);
if(nodosms.getNodeType() == Node.ELEMENT_NODE){
Element elementosms = (Element)nodosms;
NodeList listatelf = elementosms.getElementsByTagName("tlf");
Element elementotelf = (Element)listatelf.item(0);
NodeList textTelfList = elementotelf.getChildNodes();
String telefono = ((Node)textTelfList.item(0)).getNodeValue();
//String SendingAddress = ((Node)textAddressList.item(0)).getNodeValue().trim();
//System.out.println(telefono);
NodeList listaop = elementosms.getElementsByTagName("op");
Element elementoop = (Element)listaop.item(0);
NodeList textOpList = elementoop.getChildNodes();
String operadora = ((Node)textOpList.item(0)).getNodeValue();
NodeList listasc = elementosms.getElementsByTagName("sc");
Element elementosc = (Element)listasc.item(0);
NodeList textSCList = elementosc.getChildNodes();
String shortcode = ((Node)textSCList.item(0)).getNodeValue();
NodeList listabody = elementosms.getElementsByTagName("body");
Element elementobody = (Element)listabody.item(0);
NodeList textBodyList = elementobody.getChildNodes();
String body = ((Node)textBodyList.item(0)).getNodeValue();
Statement st = Conn.createStatement();
st.executeUpdate("INSERT INTO smstable (telf,op,sc,body) VALUES ('" + telefono + "','" + operadora + "','" + shortcode + "','" + body + "')");
Conn.commit();
Conn.close(); }
//Writing the SMS string to an XML file
String path;
path = Stringpath + "sms" + "0" + st + ".xml";
File f1 = new File (path);
FileWriter out1 = new FileWriter(f1);
PrintWriter wr = new PrintWriter(out1);
f1.createNewFile();
String inputLine;
//Reading the communication
while ((inputLine = lector.readLine()) != null)
wr.write(URLDecoder.decode(inputLine, "UTF-8"));
lector.close();
out1.close();
salida.println(path);
salida.println(inputLine);
//Catching errors for the SAX and XML parsing
catch (SAXParseException err)
System.out.println ("** Parsing error" + ", line " + err.getLineNumber () + ", uri " + err.getSystemId ());
System.out.println(" " + err.getMessage ());
catch (SAXException e)
Exception x = e.getException ();
((x == null) ? e : x).printStackTrace ();
catch (Throwable t)
t.printStackTrace ();

Do you get any exceptions? Any messages in the logs to tell you why this happens?
Personally, I think you should not catch a Throwable. Unchecked exceptions shouldn't be caught.
It's a good idea to code all your database logic into a separate object so you can test it off-line. If you did that, as you say, why did you cut & paste the code back into your servlet? Why not leave it inside another Java Bean that your servlet simply instantiates and invokes?
Your method is too big. You'd be better off decomposing this problem into more objects that are more discrete and cohesive.
Can't tell what went wrong based on the little you've posted. I'd be surprised if anyone had time to review this code. I know I don't. Be more specific about what's wrong and you'll have better luck.

Similar Messages

  • Php/mysql: can't write to mysql database [SOLVED]

    I'm writing a login script using php and mysql. I got it to work on my server about a week ago, and then I set up apache, php and mysql on my netbook so that I could take my code with me and test it. Now it doesn't work. My registration script doesn't write to the mysql database but has no errors. Here is register.php:
    <?php
    define("DB_SERVER", "localhost");
    define("DB_USER", "root");
    define("DB_PASS", "swordfish");
    define("DB_NAME", "users");
    define("TBL_USERS", "users");
    $connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS) or die(mysql_error());
    mysql_select_db(DB_NAME, $connection) or die(mysql_error());
    function addUser($username, $password)
    global $connection;
    $password = md5($password);
    echo("adding $username,$password<br />");
    $q = "INSERT INTO " . TBL_USERS . " VALUES ('$username', '$password')";
    echo("query: $q<br />");
    $result = mysql_query($q, $connection);
    echo("$result<br />");
    if (isset($_POST["reg"]))
    addUser($_POST["username"], $_POST["password"]);
    echo("<a href='index.php'>click here to login</a>");
    ?>
    <html>
    <head>
    <title>Register</title>
    </head>
    <body>
    <form method="Post" name="login">
    <input type="text", name="username" /> Username<br />
    <input type="text", name="password" /> Password<br />
    <input type="submit" name="reg", value="Register" />
    </form>
    </body>
    </html>
    and here is the output (without the form):
    adding lexion,6f1ed002ab5595859014ebf0951522d9
    query: INSERT INTO users VALUES ('lexion', '6f1ed002ab5595859014ebf0951522d9')
    Also, I tried manually adding the content to the database:
    $ mysql -p -u root
    Enter password:
    Welcome to the MySQL monitor. Commands end with ; or \g.
    Your MySQL connection id is 9
    Server version 5.1.42 Source distribution
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    mysql> users
    -> INSERT INTO users VALUES('lexion', 'foo')
    -> ^D
    -> Bye
    I would assume that I got something wrong with the last bit, but the php script seems like it should work. Does anybody know why it doesn't?
    Last edited by Lexion (2010-01-10 19:04:15)

    What is wrong with your PHP? Why do you think it is failing? An INSERT query doesn't return anything. Also, it's a good idea to specify which fields you are inserting into, unless you want to have to provide something for every field (tedious for tables with many fields with default values). eg:
    $q = "INSERT INTO `" . TBL_USERS . "`(`username`, `password`) VALUES ('$username', '$password')";
    As for your experiment with the mysql prompt; queries have to end with a semicolon. PHP is nice and hides that little detail from you.
    edit: Also, you're echoing text out before the HTML starts. That won't produce valid HTML. I also noticed a few other things which I corrected; look at my comments:
    <?php
    define("DB_SERVER", "localhost");
    define("DB_USER", "root");
    define("DB_PASS", "swordfish");
    define("DB_NAME", "users");
    define("TBL_USERS", "users");
    $connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS) or die(mysql_error());
    mysql_select_db(DB_NAME, $connection) or die(mysql_error());
    function addUser($username, $password)
    global $connection;
    $password = md5($password);
    // echo("adding $username,$password<br />"); - Don't echo stuff before HTML starts.
    // Also, clean up user-supplied data before plugging it into a query unless you want to be vulnerable to SQL injection.
    $cleanusername = mysql_real_escape_string($username, $connection);
    $cleanpassword = mysql_real_escape_string($password, $connection); // Obviously you'd generally use some hashing algorithm like md5 or sha1 for passwords
    $q = "INSERT INTO `" . TBL_USERS . "`(`username`, `password`) VALUES ('{$cleanusername}', '{$cleanpassword}')"; // The backticks tell MySQL not to interpret any text within as a keyword (good for field names, eg a field called `date`. The curly brackets tell PHP that the stuff within refers to a variable; it's nice as PHP knows exactly what the variable name is with no possible ambiguity.
    // echo("query: $q<br />");
    $result = mysql_query($q, $connection);
    // echo("$result<br />"); - This won't do anything; in addition to INSERT queries not returning anything, the $result variable doesn't contain the results of the query, it's a pointer to them for use with mysql_result().
    ?>
    <html>
    <head>
    <title>Register</title>
    </head>
    <body>
    <?php
    if (isset($_POST["reg"]))
    addUser($_POST["username"], $_POST["password"]);
    echo("<a href='index.php'>click here to login</a>");
    ?>
    <form method="Post" name="login">
    <input type="text" name="username" /> Username<br />
    <input type="text" name="password" /> Password<br />
    <input type="submit" name="reg" value="Register" />
    </form>
    </body>
    </html>
    <?php
    mysql_close($connection); // Not strictly needed, as PHP will tidy up for you if you forget.
    ?>
    Last edited by Barrucadu (2010-01-10 17:34:20)

  • I switched my keyboard to french and now it won't change back to english. Quite the hassle when trying to write in english. Why would it be stuck?

    I switched my keyboard to french and now it won't change back to english. Quite the hassle when trying to write in english. Why would it be stuck?

    When the keyboard pops up, tab the Globe icon, and select the English keyboard.

  • Mapping paths to servlets doesn't work anymore in SP5 ??

    Hello,
              see subject.
              I have a small web application which is contained in a WAR-file named
              "httpdump.war". Its deployment descriptor (web.xml) maps the servlet
              httpdump.HttpDumpServlet to the path /servletpath/* with the following
              XML statements:
              <servlet>
              <servlet-name>HttpDumpServlet</servlet-name>
              <display-name>The HTTP Dump Servlet</display-name>
              <servlet-class>httpdump.HttpDumpServlet</servlet-class>
              </servlet>
              <servlet-mapping>
              <servlet-name>HttpDumpServlet</servlet-name>
              <url-pattern>/servletpath/*</url-pattern>
              </servlet-mapping>
              In weblogic.properties, I have:
              weblogic.httpd.webApp.httpdump=httpdump.war
              The WAR-file is structured as follows:
              $ jar tf httpdump.war
              META-INF/
              META-INF/MANIFEST.MF
              WEB-INF/classes/httpdump/HttpDumpServlet.class
              WEB-INF/web.xml
              dummy.jsp
              $
              Now a request like http://host:port/httpdump/servletpath/xyz should be
              directed to my servlet, right?
              This works flawlessly in WLS 5.1 SP 3. With SP 5, I get the following:
              Sat Aug 26 15:58:54 CEST 2000:<E> <WebAppServletContext-httpdump> Error loading servlet: httpdump.HttpDumpServlet
              java.lang.ClassNotFoundException: httpdump.HttpDumpServlet
                   at weblogic.boot.ServerClassLoader.findLocalClass(ServerClassLoader.java:355)
                   at weblogic.boot.ServerClassLoader.loadClass(ServerClassLoader.java:111)
                   at java.lang.ClassLoader.loadClass(ClassLoader.java:243)
                   at weblogic.utils.classloaders.GenericClassLoader.parentLoadClass(GenericClassLoader.java:503)
                   at weblogic.utils.classloaders.GenericClassLoader.reallyLoadClass(GenericClassLoader.java:366)
                   at weblogic.utils.classloaders.GenericClassLoader.loadClass(GenericClassLoader.java:182)
                   at weblogic.utils.classloaders.GenericClassLoader.loadClass(GenericClassLoader.java:156)
                   at weblogic.servlet.internal.ServletStubImpl.prepareServlet(ServletStubImpl.java:371)
                   at weblogic.servlet.internal.ServletStubImpl.getServlet(ServletStubImpl.java:187)
                   at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:118)
                   at weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContextImpl.java:760)
                   at weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContextImpl.java:707)
                   at weblogic.servlet.internal.ServletContextManager.invokeServlet(ServletContextManager.java:251)
                   at weblogic.socket.MuxableSocketHTTP.invokeServlet(MuxableSocketHTTP.java:369)
                   at weblogic.socket.MuxableSocketHTTP.execute(MuxableSocketHTTP.java:269)
                   at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:135)
              Sat Aug 26 15:58:54 CEST 2000:<E> <WebAppServletContext-httpdump> Servlet failed with ServletException
              javax.servlet.ServletException: Servlet class: httpdump.HttpDumpServlet could not be loaded - the requested class wasn't found in the classpath
                   at weblogic.servlet.internal.ServletStubImpl.prepareServlet(ServletStubImpl.java:379)
                   at weblogic.servlet.internal.ServletStubImpl.getServlet(ServletStubImpl.java:187)
                   at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:118)
                   at weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContextImpl.java:760)
                   at weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContextImpl.java:707)
                   at weblogic.servlet.internal.ServletContextManager.invokeServlet(ServletContextManager.java:251)
                   at weblogic.socket.MuxableSocketHTTP.invokeServlet(MuxableSocketHTTP.java:369)
                   at weblogic.socket.MuxableSocketHTTP.execute(MuxableSocketHTTP.java:269)
                   at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:135)
              So, it seems the WLS has interpreted the <servlet-mapping> tag in the
              DD correctly, but is then looking for the servlet class in the wrong
              places..?
              My system configuration:
              $ java weblogic.Admin t3://localhost:7001 VERSION
              WebLogic Build: 5.1.0 Service Pack 5 08/17/2000 07:21:55 #79895
              $ uname -a
              Linux localhost.localdomain 2.2.14 #1 Wed Aug 16 01:57:42 CEST 2000 i686 unknown
              $ java -version
              java version "1.2.2"
              Classic VM (build 1.2.2-L, green threads, nojit)
              $
              Any hints?
              Thanks,
              Olaf
              Olaf Klischat | TU Berlin computer science
              Oberfeldstrasse 132 |
              12683 Berlin, Germany |
              phone: +49 30 54986231 | eMail: [email protected]
              

    Hi,
              we jared our servlets up and placed them in /WEB-INF/lib/....jar. The
              mapping is working without any problems.
              Daniel Hoppe
              -----Original Message-----
              From: Kumar Allamraju [mailto:[email protected]]
              Posted At: Saturday, August 26, 2000 7:57 PM
              Posted To: servlet
              Conversation: mapping paths to servlets doesn't work anymore in SP5 ??
              Subject: Re: mapping paths to servlets doesn't work anymore in SP5 ??
              Yes, this is already a known problem in SP5.
              Fix will be available in the upcoming service packs.
              I guess the workaround is to put servlet classes in servlet classpath.
              Sorry about the regression.
              Kumar
              Olaf Klischat wrote:
              > Hello,
              >
              > see subject.
              >
              > I have a small web application which is contained in a WAR-file named
              > "httpdump.war". Its deployment descriptor (web.xml) maps the servlet
              > httpdump.HttpDumpServlet to the path /servletpath/* with the following
              > XML statements:
              >
              > <servlet>
              > <servlet-name>HttpDumpServlet</servlet-name>
              > <display-name>The HTTP Dump Servlet</display-name>
              > <servlet-class>httpdump.HttpDumpServlet</servlet-class>
              > </servlet>
              >
              > <servlet-mapping>
              > <servlet-name>HttpDumpServlet</servlet-name>
              > <url-pattern>/servletpath/*</url-pattern>
              > </servlet-mapping>
              >
              > In weblogic.properties, I have:
              >
              > weblogic.httpd.webApp.httpdump=httpdump.war
              >
              > The WAR-file is structured as follows:
              >
              > $ jar tf httpdump.war
              > META-INF/
              > META-INF/MANIFEST.MF
              > WEB-INF/classes/httpdump/HttpDumpServlet.class
              > WEB-INF/web.xml
              > dummy.jsp
              > $
              >
              > Now a request like http://host:port/httpdump/servletpath/xyz should be
              > directed to my servlet, right?
              >
              > This works flawlessly in WLS 5.1 SP 3. With SP 5, I get the following:
              >
              > Sat Aug 26 15:58:54 CEST 2000:<E> <WebAppServletContext-httpdump>
              Error loading servlet: httpdump.HttpDumpServlet
              > java.lang.ClassNotFoundException: httpdump.HttpDumpServlet
              > at
              weblogic.boot.ServerClassLoader.findLocalClass(ServerClassLoader.java:35
              5)
              > at
              weblogic.boot.ServerClassLoader.loadClass(ServerClassLoader.java:111)
              > at java.lang.ClassLoader.loadClass(ClassLoader.java:243)
              > at
              weblogic.utils.classloaders.GenericClassLoader.parentLoadClass(GenericCl
              assLoader.java:503)
              > at
              weblogic.utils.classloaders.GenericClassLoader.reallyLoadClass(GenericCl
              assLoader.java:366)
              > at
              weblogic.utils.classloaders.GenericClassLoader.loadClass(GenericClassLoa
              der.java:182)
              > at
              weblogic.utils.classloaders.GenericClassLoader.loadClass(GenericClassLoa
              der.java:156)
              > at
              weblogic.servlet.internal.ServletStubImpl.prepareServlet(ServletStubImpl
              .java:371)
              > at
              weblogic.servlet.internal.ServletStubImpl.getServlet(ServletStubImpl.jav
              a:187)
              > at
              weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.
              java:118)
              > at
              weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContex
              tImpl.java:760)
              > at
              weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContex
              tImpl.java:707)
              > at
              weblogic.servlet.internal.ServletContextManager.invokeServlet(ServletCon
              textManager.java:251)
              > at
              weblogic.socket.MuxableSocketHTTP.invokeServlet(MuxableSocketHTTP.java:3
              69)
              > at
              weblogic.socket.MuxableSocketHTTP.execute(MuxableSocketHTTP.java:269)
              > at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:135)
              >
              > Sat Aug 26 15:58:54 CEST 2000:<E> <WebAppServletContext-httpdump>
              Servlet failed with ServletException
              > javax.servlet.ServletException: Servlet class:
              httpdump.HttpDumpServlet could not be loaded - the requested class
              wasn't found in the classpath
              >
              > at
              weblogic.servlet.internal.ServletStubImpl.prepareServlet(ServletStubImpl
              .java:379)
              > at
              weblogic.servlet.internal.ServletStubImpl.getServlet(ServletStubImpl.jav
              a:187)
              > at
              weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.
              java:118)
              > at
              weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContex
              tImpl.java:760)
              > at
              weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContex
              tImpl.java:707)
              > at
              weblogic.servlet.internal.ServletContextManager.invokeServlet(ServletCon
              textManager.java:251)
              > at
              weblogic.socket.MuxableSocketHTTP.invokeServlet(MuxableSocketHTTP.java:3
              69)
              > at
              weblogic.socket.MuxableSocketHTTP.execute(MuxableSocketHTTP.java:269)
              > at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:135)
              >
              > So, it seems the WLS has interpreted the <servlet-mapping> tag in the
              > DD correctly, but is then looking for the servlet class in the wrong
              > places..?
              >
              > My system configuration:
              >
              > $ java weblogic.Admin t3://localhost:7001 VERSION
              > WebLogic Build: 5.1.0 Service Pack 5 08/17/2000 07:21:55 #79895
              >
              > $ uname -a
              > Linux localhost.localdomain 2.2.14 #1 Wed Aug 16 01:57:42 CEST 2000
              i686 unknown
              >
              > $ java -version
              > java version "1.2.2"
              > Classic VM (build 1.2.2-L, green threads, nojit)
              > $
              >
              > Any hints?
              >
              > Thanks,
              > Olaf
              > --
              > Olaf Klischat | TU Berlin computer science
              > Oberfeldstrasse 132 |
              > 12683 Berlin, Germany |
              > phone: +49 30 54986231 | eMail: [email protected]
              

  • When i call someone who already connected with another call it doesn't show any wating notification. why? it is very important. all other mobiles have this potion. Please give me some solution.

    when i call someone who already connected with another call it doesn't show any wating notification. why? it is very important. all other mobiles have this option. Please give me some solution.

    Your iPhone can take multiple calls. If you answer your phone from one person or call someone and another call comes into you, you will hear a beep and if you pull your phone away from your ear, you will see that you can hang up the call with the 1st person or answer the 2nd call and then swap between the two.
    I have no idea what you mean by you calling someone who is already talking to someone. I've never been able to see on my iPhone that someone I'm calling is already talking to someone else.

  • *** Example of JSF Image servlet that can write image to network drive ??

    Hi Guys,
    Does anyone have an example of a of JSF Image servlet that can Write image to network drive ??
    I can write an image to my local drive on my tomcat app server. But when I try to map to a network drive with IP or Mapped drive it fails.
    Any help out there ??
    Thanks
    Phil

    Hi,
    The drive I am trying to access is on a box 45.65.111.115 ip
    I have mapped the box and drive to M:
    Setting sharing on...
    I have tried a few new ways...
    imageDrive2=M:\\test_images\\
    gives this errror
                java.io.FileNotFoundException: M:\test_images\first250k\16Sep0857_Phil_Tucson.JPG (The system cannot find the path specified)
         at java.io.RandomAccessFile.open(Native Method)
         at java.io.RandomAccessFile.<init>(RandomAccessFile.java:212)
         at javax.imageio.stream.FileImageOutputStream.<init>(FileImageOutputStream.java:44)=============================================
    imageDrive3=\\\\45.65.111.115\\first250k\\test3.jpg
    gives this errror
    java.io.FileNotFoundException: \\45.65.111.115\first250k\test3.jpg (Access is denied)
         at java.io.RandomAccessFile.open(Native Method)
         at java.io.RandomAccessFile.<init>(RandomAccessFile.java:212)
         at javax.imageio.stream.FileImageOutputStream.<init>(FileImageOutputStream.java:44)
         at com.sun.imageio.spi.FileImageOutputStreamSpi.createOutputStreamInstance(FileImageOutputStreamSpi.java:37)========================================================
    imageDrive4=\\\\45.73.111.115\\test_images\\test4.jpg
    gives this errror
    java.io.FileNotFoundException: \\45.73.111.115\test_images\test4.jpg (Access is denied)
         at java.io.RandomAccessFile.open(Native Method)
         at java.io.RandomAccessFile.<init>(RandomAccessFile.java:212)
         at javax.imageio.stream.FileImageOutputStream.<init>(FileImageOutputStream.java:44)
         at com.sun.imageio.spi.FileImageOutputStreamSpi.createOutputStreamInstance(FileImageOutputStreamSpi.java:37)
         at javax.imageio.ImageIO.createImageOutputStream(ImageIO.java:391)
         at javax.imageio.ImageIO.write(ImageIO.java:1483)=============================================================================
    Any help out there??
    Phil

  • CD drive doesn't write CDs

    Help me please!!! My CD drive doesn't write CDs, but it still can clean CD-RW. What should i do?

    Did you enable the burning function on the drive?
    This can be done in the drive properties.
    Furthermore did you use the burning application for example Nero?
    I agree with Ivan. I think you should additional test different Medias because not every CD is compatible with the drive.
    In the user manual you should find the list with compatible medias. In my user manual I have found such list.

  • I swtiched from LabView7 to LabView8.2, and now my parallel port on LPT1 is not more recognised (I am not able to use VISA to write on it). Why?

    I switched from LabView7 to LabView8.2, and now my parallel port on LPT1 is not more recognised (I am not able to use VISA to write on it). Why?

    Hi,
    Sorry for the delay,
    I need to know more informations about your problem. Have you check the configuration of LPT in MAX? Can you open a VISA session? Do you receive a timeout error when you try to write on that port?
    You can find same importants informations about parallel port configuration for different versions of LabVIEW at this link: 
    http://digital.ni.com/public.nsf/websearch/E6415E8A8376F63D86256C46007592E8?OpenDocument
    Let's me know.
    Riccardo

  • After Updating the iOS 7.04 on my iPhone 4s drain battery quickly on standby mode & also doesn't respond volume up button, why?

    After Updating the iOS 7.04 on my iPhone 4S drain battery quickly even on standby mode & also doesn't respond volume up button, why?

    My battery problem woes continues to persist.  Yesterday, I had about 85-90% battery life in the morning.  A couple hours later when I looked at the phone it was down to 65%.  At that point, I shut off wi-fi, bluetooth, and background app refresh.  I received one call shortly after that.  The call lasted about two minutes.  My battery was now down to 40%.  Another hour later, down to 16%!  Here's the kicker:  I plugged in the phone to a charger and it jumped to 65% in a matter of minutes.  I unplugged the phone and within a couple of hours it was back down to around 30%.  I plugged it in again and within 10 minutes it was up to 75%.
    At first glance it looks very much like a hardware issue.  However, I never had this problem until I upgraded to 7.0.4.  Also, the above battery roller coaster ride isn't a constant.  That is, it seems that only sometimes this happens.  So...I'm thinking it's either an app running in the background eating up juice (though I have Background App Referesh turned off) or the iOS is buggy. 

  • There's a problem with my pervious purchase and it doesn't let me change cards why?

    There's a problem with my pervious purchase and it doesn't let me change cards why?

    Ashtin123 wrote:
    There's a problem with my pervious purchase..
    Then you need to Contact iTunes Customer Service
    Use this Link  >  Apple  Support  iTunes Store  Contact

  • HT5312 The link so you can reset your security question doesn't send to my email why ?

    The link so you can reset your security question doesn't send to my email why ? Why can you guys take out those question when nobody is gonna try to hack your account ,everything you need is a strong password .

    We are fellow users here on these user-to-user forums, you're not talking to iTunes Support nor Apple.
    If you aren't receiving the email to your rescue email account (and you've checked the spam folder on that account and tried clicking the reset link again) then you will need to contact Support in your country to get the questions reset.
    Contacting Apple about account security : http://support.apple.com/kb/HT5699
    When they've been reset then if it's available in your country you could change to 2-step verification instead : http://support.apple.com/kb/HT5570

  • TS1702 My iphone wont download any apps. It lets me enter password but then the app just flicks back to the price and doesn't download. Any idea why?

    My iphone wont download any apps. It lets me enter password but then the app just flicks back to the price and doesn't download. Any idea why?
    It was fine until i updated to iOS 5

    Have you tried:
    1. Resetting your iPad; hold down the Sleep and Home button for about 10 seconds until you see the Apple logo.
    2. Turn OFF your router for 30 seconds and ON again.

  • Why my servlet doesn't run

    Hi, all
    Ask a stupid question, i install tomcat 4.1.31, i can see those sample servlet, even i put my sample servlet into example folder, i still can see them. However, when i want to see http://localhost/servlet/HelloServlet
    It gives me this error messge:
    The requested resource (/servlet/HelloServlet) is not available.
    I checked my classpath, and make sure all folders are correct, it still gives me the same error.
    Can anyone advise it?
    Thanks
    David

    hi dawang.... even i encountered the same problem when i used servlet the first time... make sure ur storing ur servlet class file in the url.. webapps\oot/web-inf\classes\helloservlet .. if its is correct then u just need to enable the invoker servlet.. for this go to the conf\web.xml ...open the xml file and do the following changes
    To enable the invoker servlet, uncomment the following servlet and servlet-mapping elements in install_dir/conf/web.xml. Do not confuse this Apache Tomcat-specific web.xml file with the standard one that goes in the WEB-INF directory of each Web application.
    <servlet>
    <servlet-name>invoker</servlet-name>
    <servlet-class>
    org.apache.catalina.servlets.InvokerServlet
    </servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>invoker</servlet-name>
    <url-pattern>/servlet/*</url-pattern>
    </servlet-mapping>
    it worked with my tomcat 5.5.7.. and hope it goes the same with u... and anyways if u don't want to save ur servlet in the root directory... make ur own webapplication inside the webapps directory and use the following url... http://localhost:8080/webappname/servlet/helloservlet... or if the file is saved in root directory use the following http://localhost:8080/servlet/helloservlet...
    make sure ur not using any package to store ur servlet or using a package in ur servlet prog...
    if ur doing so... just make another directory in ur classes directory.. with the same name as ur package and store the servlet class file there
    and use the following url
    http://localhost:8080/servlet/pacakagename.helloservlet
    mind u 8080 is the default port no. of my tomcat installlation.. if u have anyother port no.. do mention that.
    i hope this would help u solve ur problem...

  • BAPI doesn't write data to database? why?

    Hi,
    I am using my web dynpro app to call BAPI_PR_CREATE, BAPI_RESERVATION_CREATE1.
    all the input is right, and it returns me a Purchase No, and Reservation No, but when i check the number against the database, they have not been created.
    why is this happening? how to solve?
    thanks!

    While executing in se37,Select Test Sequences from se37 menu .Give BAPI_PR_CREATE, BAPI_TRANSACTION_COMMIT and then execute it one by one.
    if we are using the bapi in a report,then u can use commit work command .
    i m no sap gui expert, how to do this exactly.
    i add BAPI_PR_CREATE and BAPI_TRANSACTION_COMMIT one by one to the list
    then i excute it, i chose a set of test data from the list where it's going to provide me with a correct result.
    then click excute, the PR_CREATE got excuted
    then how to proceed to the next level?
    thanks

  • Servlet with Issues writing to MySQL Database using JNDI

    I'm hung on one servlet for my site. It compiles fine, and is accessed fine by the JSP, but doesn't do as I intended: write my blog entries to the MySQL database!
    As mentioned in the title, I'm using JNDI for connection pooling, via META-INF/context.xml.
    I'm also using JDBC Realm with a form, and that's working just fine, so I'm sure my issue isn't context.xml, as it seems to be overriding Tomcat's context file just fine, at least for authentication.
    Below is the code from the servlet, to include the annotations:
    package projectEgress.web.blog;
    import java.io.*;
    import java.text.*;
    import java.sql.*;
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import javax.naming.NamingException;
    import javax.sql.*;
    public final class blogInput {
         /* bean properties */
        private String blogHeader;
        private String blogSubheader;
        private String blogBody;
        private String externalLinks;
        Connection conn;
        Statement stmt;
            /* getters & setters */
            public String getBlogHeader() {
                return blogHeader;
            public void setBlogHeader(String blogHeader) {
                this.blogHeader = blogHeader;
            public String getBlogSubheader() {
                return blogSubheader;
            public void setBlogSubheader(String blogSubheader) {
                this.blogSubheader = blogSubheader;
            public String getBlogBody() {
                return blogBody;
            public void setBlogBody(String blogBody) {
                this.blogBody = blogBody;
            public String getExternalLinks() {
                return externalLinks;
            public void setExternalLinks(String externalLinks) {
                this.externalLinks = externalLinks;
            /* like it says, a void which writes to the database */
            public void writeToDatabase() {
                /* create the query string to fill the table */
                String query = "insert into blogEntry (blogHeader, blogSubheader, blogBody, externalLinks) values (\"" + this.blogHeader + "\", \"" + this.blogSubheader + "\", \"" + this.blogBody + "\", \""  + this.externalLinks + "\")";
                try {
                    /*establish the datasource and make the connection */
                    Context ctxt =  new InitialContext();
                    DataSource dsrc = (DataSource)ctxt.lookup("java:comp/env/jdbc/projectEgress");
                    conn = dsrc.getConnection();
                    stmt = conn.createStatement();
                    /* Add data to table 'blogEntry' in our database */
                    int input = stmt.executeUpdate(query);
                    /* close the connections */
                    stmt.close();
                    conn.close();
                    /* check for exceptions, ensure connections are closed */
                    } catch (SQLException sqlx) {
                        sqlx.printStackTrace();
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    } finally {
                        if (stmt != null) {
                            try {
                                stmt.close();
                        } catch (SQLException sqlx) {}
                        if (conn != null) {
                            try {
                                conn.close();
                        } catch (SQLException sqlx) {}
            Here are the settings I have in META-INF/context.xml (sans Realm stuff, which works):
    <Context debug="1" reloadable="true">
        <Resource name="jdbc/projectEgress"
            auth="Container"
            type="javax.sql.DataSource"
            username="********"
            password="********"
            driverClassName="com.mysql.jdbc.Driver"
            url="jdbc:mysql://localhost:3306/projectEgress?autoReconnect=true"
            validationQuery="select 1"
            maxActive="15"
            maxIdle="8"
            removeAbandoned="true"
            removeAbandonedTimeout="120" />
        <WatchedResource>WEB-INF/web.xml</WatchedResource>
        <WatchedResource>META-INF/context.xml</WatchedResource>
    </Context>And, finally, the code I'm using in the JSP which calls the method (the form action is directed to this file's URL):
        <jsp:useBean id="blogInput" class="projectEgress.web.blog.blogInput">
        <jsp:setProperty name="blogInput" property="*" />
            <jsp:scriptlet>blogInput.writeToDatabase();</jsp:scriptlet>
        </jsp:useBean>
        -YES, I know I'm using a scriptlet in a JSP... I really don't want to create a custom tag to call the method, at least not until I'm far along enough in the project to justify creating a library... let's make it all work, first! :o)
    FINALLY, the form:
    <form action="/projectEgress/area51/blogInput" method="post" id="adminForm" enctype="application/x-www-form-urlencoded">
         <div>
            <span class="inputheader">Blog Header</span><br />
          <input type="text" name="blogHeader" size="35" class="form" /><br />
            <span class="inputheader">Blog SubHeader</span><br />
          <input type="text" name="blogSubheader" size="45" class="form" /><br />
            <span class="inputheader">Blog Body</span><br />
          <textarea class="content" name="blogBody" rows="9" cols="60"></textarea><br />
            <span class="inputheader">External Links</span><br />
          <input type="text" name="externalLinks" size="45" class="form" /><br />
          <input type="submit" value="Post!" class="submit" />
         </div>
        </form>As far as I can tell, it should work, and it doesn't throw any errors (in fact it shows the success message rather than the configured error page), but when I check the blogEntry table from the MySQL prompt, it responds with "Empty set".
    I've double checked to ensure that the table columns are present in MySQL and all the naming conventions line up and they do, so I figure it's my servlet that's broken.
    Advice? Ideas?
    Thanks in advance.
    Edited by: -Antonio on Apr 25, 2008 8:03 PM with additional info

    Okay, I changed a few things in the servlet code.
    For one, I'm trying a PreparedStatement in place of Statement. Don't ask me what made me think it would work any better, it just stores the sql query in cache, but I thought I'd just try something else.
    One thing this is allowing me to do is make the connection and statement (now PreparedStatement pStmt) objects local variables. It wouldn't allow me to do so before without giving me compile errors.
    package projectEgress.web.blog;
    import java.io.*;
    import java.text.*;
    import java.sql.*;
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import javax.naming.NamingException;
    import javax.sql.*;
    public final class blogInput {
         /* bean properties */
        private String blogHeader;
        private String blogSubheader;
        private String blogBody;
        private String externalLinks;
            /* getters & setters */
            public String getBlogHeader() {
                return blogHeader;
            public void setBlogHeader(String blogHeader) {
                this.blogHeader = blogHeader;
            public String getBlogSubheader() {
                return blogSubheader;
            public void setBlogSubheader(String blogSubheader) {
                this.blogSubheader = blogSubheader;
            public String getBlogBody() {
                return blogBody;
            public void setBlogBody(String blogBody) {
                this.blogBody = blogBody;
            public String getExternalLinks() {
                return externalLinks;
            public void setExternalLinks(String externalLinks) {
                this.externalLinks = externalLinks;
            /* like it says, a void which writes to the database */
            public synchronized void writeToDatabase() {
                Connection conn = null;
                PreparedStatement pStmt = null;
                /* create the query string to fill the table */
                String Query = "INSERT INTO blogEntry (blogHeader, blogSubheader, blogBody, externalLinks) VALUES (\"" + this.blogHeader + "\", \"" + this.blogSubheader + "\", \"" + this.blogBody + "\", \""  + this.externalLinks + "\")";
                try {
                    /*establish the datasource and make the connection */
                    Context ctxt =  new InitialContext();
                    DataSource dsrc = (DataSource)ctxt.lookup("java:comp/env/jdbc/projectEgress");
                    conn = dsrc.getConnection();
                    pStmt = conn.prepareStatement(Query);
                    /* Add data to table 'blogEntry' in our database */
                    pStmt.executeUpdate();
                    pStmt.clearParameters();
                    /* close the connections */
                    pStmt.close();
                    conn.close();
                    /* check for exceptions, ensure connections are closed */
                    } catch (SQLException sqlx) {
                        sqlx.printStackTrace();
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    } finally {
                        if (pStmt != null) {
                            try {
                                pStmt.close();
                        } catch (SQLException sqlx) {}
                        if (conn != null) {
                            try {
                                conn.close();
                        } catch (SQLException sqlx) {}
    }Someone out there has to have a thought on this.
    Even if it's just something they think probably won't work, so long as it gives me another angle to see this from.

Maybe you are looking for