Trouble in PreparedStatement

Here is my code, and errfile. The code is very simple. It can run on the windows2000. The errors are reported when it is running on the linux. It has confused me two weeks. My God
If you know the answer, please email me. [email protected]
import java.sql.*;
import java.util.*;
public class InsertDatabase{
String url;
Connection con ;
public static void main(String args[])throws Exception{
InsertDatabase j=new InsertDatabase();
if(args.length < 2){
System.out.println("\n"+"Usage java InsertDatabase -i no name"+"\n");
return;
if(args[0].equals("-i")) j.start(Integer.parseInt(args[1]), args[2]);
}//main
public void start(int empno, String ename)throws Exception{
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
url = "jdbc:oracle:oci8:@";
con = DriverManager.getConnection (url, "scott", "tiger");
PreparedStatement pstmt = con.prepareStatement("insert into emp (empno) values (?)");
//// Add LESLIE as employee number 1500
pstmt.setInt (1, empno); // The first ? is for EMPNO
//// Do the insertion
pstmt.execute ();
pstmt.close();
con.close();
}///~
The following is errors reported by the compiler:
java.lang.ExceptionInInitializerError: [exception was kaffe.util.SupportDisabled: GNU gmp was not found by Kaffe configure script]
at oracle.jdbc.dbaccess.DBConversion.IntToNumberBytes(DBConversion.java:line unknown, pc 0x82c206e)
at oracle.jdbc.driver.OraclePreparedStatement.setInt(OraclePreparedStatement.java:line unknown, pc 0x8361d64)
at InsertDatabase.start(InsertDatabase.java:33)
at InsertDatabase.main(InsertDatabase.java:20)
kaffe.util.SupportDisabled: GNU gmp was not found by Kaffe configure script
at java.lang.Throwable.fillInStackTrace(Throwable.java:native)
at java.lang.Throwable.<init>(Throwable.java:38)
at java.lang.Error.<init>(Error.java:21)
at kaffe.util.SupportDisabled.<init>(SupportDisabled.java:22)
at java.math.BigInteger.initialize0(BigInteger.java:native)
at java.math.BigInteger.<clinit>(BigInteger.java:30)
at java.math.BigDecimal.<init>(BigDecimal.java:36)
at oracle.jdbc.dbaccess.DBConversion.IntToNumberBytes(DBConversion.java:line unknown, pc 0x82c206e)
at oracle.jdbc.driver.OraclePreparedStatement.setInt(OraclePreparedStatement.java:line unknown, pc 0x8361d64)
at InsertDatabase.start(InsertDatabase.java:33)
at InsertDatabase.main(InsertDatabase.java:20)

I think you will have to use the thin driver. I don't think there is an oci8 driver in the linux Oracle release ...at least that was the conclusion I came to.

Similar Messages

  • Troubled with PreparedStatement, please help

    Hello all:
    Here is a seemingly too simple a problem which is already taking my day. Please help.
    String x=null;
    String querry1 = null;
    String querry2 = null;
    ResultSet rs = null;
    Statement st = null;
    PreparedStatement pstmt = null;
    try {
    st = conn.createStatement();
    //MAKE FIRST QUERRY
    querry1 = "SELECT * FROM table1 WHERE (a= ? OR b = ?)";
    pstmt = conn.prepareStatement(querry1);
    pstmt.setString(1, userInput);
    pstmt.setString(2, userInput);
    rs = pstmt.executeQuery();
    while(rs.next()){
    //Process the result set.
    //The value of x is one of the values in the result set.
    //Hence get it.
    x = rs.getString("C");
         }//end while
    //No problem up to here.
    //For check, output the value of x
    System.out.println(x); //correct non-null value is displayed
    //MAKE SECOND QUERRY based on the value of 'x'
    querry2 = "SELECT * FROM table2 WHERE C= ? ";
    //Table 1 and table 2 have a common column C.
    //I want to retrieve the value from table 2 for which C=x;
    pstmt = conn.prepareStatement(querry2);
    pstmt.setString(1, x);
    rs = pstmt.executeQuery();
    //The problem is that in this 2nd querry, SQL error is caught, with the message
    "java.sql.SQLException: Illegal operation on empty result set"
    //whereas it should have produced a valid value.
    //When the querry is formed explicitly (as follows), there is no problem. Result set is OK.
    //when the value of x is "mystring", then the follwoing 3 lines work
    pstmt = conn.prepareStatement(querry2);
    pstmt.setString(1, "mystring");
    rs = pstmt.executeQuery();
    Please teach me what the hell I'm not getting here.
    Thank you.

    I would have thought you'd get this exception:
    "java.sql.SQLException: Illegal operation on empty result set"
    because you're trying to call something like:
    rs.getString("foo");on an empty ResultSet. You can test whether the ResultSet has any rows as ResultSet.next() returns a boolean value, i.e.:
    if (rs.next())
        rs.getString("foo");
    }So the question is why is your second ResultSet empty? Maybe the value of C you are getting from table1 has leading/trailing whitespace that is not in table2?

  • PreparedStatement and CHAR columns

    Hi
    I am having troubles using preparedStatements on tables with columns of type CHAR:
    My table has a column of type CHAR(3). The data in this column is 0,1,2 or three characters long.
    My query contains this column in the WHERE clause in the from "WHERE colName = ?".
    The problem is now, that I have to use a String in the pstmt.setString(1, str) statement that is exactly 3 characters long. Otherwise I don't get any result.
    If I use a 2 char string i get nothing. But with a 'normal' statement or in SQL*Plus it works perfectly fine.
    Of course, I could trim() my column or fill the string up to be always 3 chars, but I think that's not state of the art.
    Any other solutions?
    Thanks in advance.
    Andres
    null

    What you describe is the ANSI behavior of a CHAR column. VARCHAR columns can match on any length (and can be any length up to the maximum or the column constrint limit), but a char column is required to be blank padded. If you must use CHAR then write a function to automatically pad the string for you so that it will match.

  • Having trouble passing a getter method in a PreparedStatement

    Basically I've got it so that the user fills in their name, dob etc and when they click on register it inserts their information in a registrations table. However, I'm having trouble getting this working (NullPointerException) so any help would be greatly appreciated :)
    RegisterDetails.java
    public void writeToTbl() throws SQLException, ClassNotFoundException {
              DBase d = new DBase();
              GUI g = new GUI();
              i = 0;
              String regStr = "INSERT INTO REGISTRATION VALUES(?,?,?,?,?,?,?,?)";
              PreparedStatement st = d.getConnection().prepareStatement(regStr);          
              st.setInt(1, i);
              st.setString(2, g.getName()); //Exception error points to this line
              st.setString(3, g.getDOB());
              st.setString(4, g.getRoad());
              st.setString(5, g.getCity());
              st.setString(6, g.getCounty());
              st.setString(7, g.getPhone());
              st.setString(8, g.getEmail());
              st.executeUpdate();
         }GUI.java
    btnReg.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent ev) {               
                        if (ev.getSource() == btnReg && (agree.isSelected())) {
                             writeToFile(f, bWriter);
                             RegisterDetails reg = new RegisterDetails();
                             try {
                                  reg.writeToTbl(); //Exception error points to this line
                             } catch (SQLException e) {
                                  e.printStackTrace();
                             } catch (ClassNotFoundException e) {
                                  e.printStackTrace();
                        else {
    // JTextFields return their results
    public String getName() {
              return name.getText(); //Exception error points to this line
         public String getDOB() {
              return dob.getText();
         public String getRoad() {
              return road.getText();
         public String getCity() {
              return city.getText();
         public String getCounty() {
              return county.getText();
         public String getPhone() {
              return phoneNo.getText();
         public String getEmail() {
              return email.getText();So essentially I'm trying to get the information from the textfields and insert it into the registrations table but nothing seems to work. I've followed numerous tutorials on how to do it, but all of them use "fixed" values e.g., setString(1, "James") etc but I need the value of the JTextFields as they will be different every time. I'm completely at a loss with this at the moment so any help would be magnificent. :-)
    Thank you!

    so any help would be magnificent.Write a class that accepts the values that you want to insert. I would suggest passing an ArrayList. It opens the connection, does the insert, closes the statement and the connection.
    It does NOT have any GUI code in it.
    You then debug that class and verify it works.
    THEN, after you have verified it works, you write ANOTHER class that does the gui. It uses the class above to do the database work.

  • A trouble with "LIKE" in a select statement

    Hi!
    I'm having trouble with "LIKE" in a select statement...
    With Access I can make the following and everything works well:
    SELECT name, birthday
    FROM client
    WHERE birthday LIKE '*/02/*';
    but if try to do it in my application (it uses Access), it doesn't work - I just can't understand that!!!
    In my application the "month" is always the currently month taken from the "System". Look what I'm doing...
    String query1 = "SELECT name, birthday " +
              "FROM client " +
              "WHERE birthday " +
              "LIKE '*/" +
              pMonth +
              "/*' " +
              "ORDER BY birthday ASC ";
    ResultSet rs = statement1.executeQuery(consulta1);
    boolean moreRecords = rs.next();
    The variable "moreRecords" is always "false", the query returns nothing although the table "client" has records that attend the query.
    Please, anyone can help me?! It's a little bit urgent.
    Thanks,
    Katia.

    Hi Katia,
    I'll bet the problem lies with the characters you're using to escape the LIKE clause. You're using the ones that Access likes to see, but that's not necessarily what's built into the JDBC-ODBC driver class.
    You can find out what the correct escape wildcard characters are from the java.sql.DatabaseMetaData.getSearchStringEscape() method. It'll tell you what to use in the LIKE clause.
    I'm not 100% sure about your code. It doesn't use query1 anywhere. I'd do this:
    String query = "SELECT name, birthday FROM client WHERE birthday LIKE ? ORDER BY birthday ASC";
    PreparedStatement statement = connection.createStatement(query);
    String escape = connection.getMetaData().getSearchStringEscape();
    String test = escape + '/' + pMonth + '/' + escape;
    statement.setString(1, test);
    ResultSet rs = statement.executeQuery();
    while (rs.hasNext())
    // load your data into a data structure to pass back.
    rs.close();
    statement.close();Let me know if that works. - MOD

  • SQL INSERT trouble- please help

    I'm having an trouble,to INSERT a record to my db.(MySQL)
    This is the condition.
    There is a form to validate the NicNo,which is input by the user.If it it exist, then the system displays an error msg. If it is not,display a new form to enter the candidate details.Then the user can save them to the db.These are working well.But,when I go to the mySQL console and check,the record is nicely saved except 2 fields.(civilStatus and eduQua).
    Did you know why? I check my prepared statement,I think it's OK.
    Here are the codes:
    The form which is used by the user to input NicNo.
    <%@ page session="false" %>
    <%@ page import="java.sql.*,java.util.*,javax.servlet.http.*" %>
    <form method="POST" action="EntInterProcess.jsp">
        <center>
            <div align="center">
        <center>
       <TABLE borderColor=burlywood cellSpacing=0 cellPadding=1
                width="256" borderColorLight=moccasin border=1>
          <tr>
            <td noWrap style="background-color: #DEB887" width="80"><B>NIC No</b></td>
            <td width="106">
            <input type="text" name="nicno" size="14" style="border:1px solid #0000FF;
    color: #FF0000; font-weight: bold"></td>
            <td width="56"><input type="submit" value="Select" name="B1"></td>
          </tr>
         </table>
           </center>
      </div>
    </form>The file called "EntInterProcess.jsp"
    <%@ page import="core.CandidateMgr" %>
    <jsp:useBean id="CandidateMgr" class="core.CandidateMgr" scope="session"/>
    <jsp:setProperty name="CandidateMgr" property="*"/>
    <%
    String nextPage ="MainForm.jsp";
    if(CandidateMgr.verifyNicNo()){
         nextPage="InterviewForm.jsp";
         }else{
         nextPage="ExitError.jsp";
    %><jsp:forward page="<%=nextPage%>"/>I didn't copy here the page called "InterviewForm.jsp",because it has many fields.If you want please tell me.So I copy here the CandidateMgr.java file, which is the javaBean.
    package core;
    import java.io.*;
    import java.sql.*;
    import java.util.*;
    import javax.sql.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class CandidateMgr
       private String nicno;
       private String name
       private String address;
       private String civilStatus;
       private String tele;
       private String eduQua;
         // Constructor
         public CandidateMgr()
       * Returns the nicno.
       public String getNicno()
          return nicno;
       * Sets the nicno.
       public void setNicno(String nicno)
          this.nicno = nicno;
       * Returns the name.
       public String getName()
          return name;
       * Sets the name.
       public void setName(String name)
          this.name = name;
       * Returns the address.
       public String getAddress()
          return address;
       * Sets the address.
       public void setAddress(String address)
          this.address = address;
       * Returns the civilStatus.
       public String getCivil()
          return civilStatus;
       * Sets the civilStatus.
       public void setCivil(String civilStatus)
          this.civilStatus= civilStatus;
       * Returns the tele.
       public String getTele()
          return tele;
       * Sets the tele.
       public void setTele(String tele)
          this.tele= tele;
       * Returns the eduQua.
       public String getEdu()
          return eduQua;
       * Sets the eduQua.
       public void setEdu(String eduQua)
          this.eduQua= eduQua;
         public boolean verifyNicNo(){
              boolean nic_no_select_ok = false;
              String nic="xxxx";
              try{
                   String DRIVER = "com.mysql.jdbc.Driver";
                   java.sql.Connection conn;
                   String URL = "jdbc:mysql://localhost:3306/superfine";
                    //Open the database
                   Class.forName(DRIVER).newInstance();
                   Connection con=null;
                   PreparedStatement pstmt1 = null;
                   con = DriverManager.getConnection(URL);
                   String sql="SELECT * FROM Candidate where nicNo= ?";          
                   pstmt1 = con.prepareStatement(sql);
                   pstmt1.setString(1,nicno);
                   ResultSet rs1 = pstmt1.executeQuery();
                                while(rs1.next()){
                        nic=rs1.getString("nicNo");
                   if(nic=="xxxx")
                        nic_no_select_ok = true;
                   } else{
                        nic_no_select_ok = false;     
                   rs1.close();
                           pstmt1.close();
                   con.close();
                catch(ClassNotFoundException e1){
                   System.err.println(e1.getMessage());
                catch(SQLException e2){
                           System.err.println(e2.getMessage());
               catch (java.lang.InstantiationException e3) {
                    System.err.println(e3.getMessage());
              catch (java.lang.IllegalAccessException e4) {
                    System.err.println(e4.getMessage());
              catch (java.lang.NullPointerException e5){
                   System.err.println(e5.getMessage());
              return nic_no_select_ok;
         public boolean addInter(){
              boolean add_inter_ok = false;
              try{
                   String DRIVER = "com.mysql.jdbc.Driver";
                   java.sql.Connection conn;
                   String URL = "jdbc:mysql://localhost:3306/superfine";
                    //Open the database
                   Class.forName(DRIVER).newInstance();
                   Connection con=null;
                   PreparedStatement pstmt3=null;
                   con = DriverManager.getConnection(URL);
                   String sqle ="INSERT INTO Candidate VALUES(?,?,?,?,?,?)";
                   pstmt3 = con.prepareStatement(sqle);
                   //assign value for ???
                   pstmt3.setString(1, nicno);
                   pstmt3.setString(2, name);
                   pstmt3.setString(3, address);
                   pstmt3.setString(4, civilStatus);
                   pstmt3.setString(5, tele);
                   pstmt3.setString(6, eduQua);
                   if(pstmt3.executeUpdate()==1) add_inter_ok=true;
                   pstmt3.close();
                           con.close();
                catch(ClassNotFoundException e1){
                   System.err.println(e1.getMessage());
                catch(SQLException e2){
                           System.err.println(e2.getMessage());
               catch (java.lang.InstantiationException e3) {
                    System.err.println(e3.getMessage());
              catch (java.lang.IllegalAccessException e4) {
                    System.err.println(e4.getMessage());
              return add_inter_ok;
    }These are the codes which I use to do this task.I don't know what happend to that 2 fields(they save in the db as NULL).Is there a nice method to do this database declaration? I try to declare that part as
    a seperate class,but I don't know how to code that by using java and call it to other sections for reuse.
    Anyone can answer these questions,please tell me how to do this,because it's urgent.
    Thanks.

    Hi Casabianca,
    Your code looks okay. I have just a couple of questions:
    (1) Are you 100% certain that those columns are of type VARCHAR/String in your MySQL database?
    (2) You only have a default ctor for your core.CandidateMgr class, and it has no implementation at all. That means that the six private member Strings are all set to null.
    Your addInter() method inserts the current values of the private data members into MySQL. If it so happened that those two fields, civilStatus and eduQua, were never initialized using calls to their respective setters, then their values would still be null because you never set them to sensible values inside the constructor.
    I'd do two things:
    (1) Add code to your default constructor to set all the strings to the empty string.
    (2) Write a second constructor that allows a user to initialize all six strings when the object is created. That way you can have a fully-initialized instance of CandidateMgr without having to call the setters. Have your default ctor simply call this second ctor:
    public CandidateMgr()
        this("", "", "", "", "", "");
    public CandidateMgr(final String nicno, final String name, final String address, final String civilStatus, final String tele, final String eduQua)
      this.nicno = nicno;  
      this.name  = name;
      this.address = address;  
      this.civilStatus = civilStatus;  
      this.tele = tele;  
      this.eduQua = eduQua;
    }Always write a constructor so the object is ready for use right away.
    See if that fixes your problem. The JDBC code looks okay.

  • Trouble while passing an array as a parameter to an JDBC Control

    Hi everyone, recently I have upgraded my WLS Workshop 8.1 application to WLS 10gR3 using the workshop 8.1 application upgrade but after the upgrade to beehive controls I'm having troubles in a couple of methods that receive an array as a parameter. One of the methods is the following:
    * @jc:sql array-max-length="all" max-rows="all"
    * statement::
    * select COUNT(*) FROM (
    * SELECT la.lea_gkey,la.eme_gkey
    * FROM (SELECT gkey, name, role FROM employees WHERE {sql:fn in(gkey,{emeGkeyArray})}) e,
    * lead_assignees la,
    * leads le,
    * cities ct,
    * (select lea_gkey,name,email,phone,title from contacts where principal = 'X') cn,
    * (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TARGET') targets,
    * (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TOP5') top5,
    * (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TOP100') top100
    * WHERE e.gkey = la.eme_gkey
    * AND la.lea_gkey = le.gkey
    * AND le.city = ct.gkey(+)
    * AND le.gkey = cn.lea_gkey(+)
    * AND le.gkey = targets.lea_gkey(+)
    * AND le.gkey = top5.lea_gkey(+)
    * AND le.gkey = top100.lea_gkey(+)
    * {sql: whereClause}
    * UNION
    * SELECT DISTINCT la.lea_gkey,la.eme_gkey
    * FROM (SELECT gkey, name, role FROM employees WHERE {sql:fn in(gkey,{emeGkeyArray})}) e,
    * lead_assignees la,
    * shared_accounts sa,
    * leads le,
    * cities ct,
    * employees asign,
    * (select lea_gkey,name,email,phone,title from contacts where principal = 'X') cn,
    * (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TARGET') targets,
    * (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TOP5') top5,
    * (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TOP100') top100
    * WHERE e.gkey = sa.eme_gkey
    * AND asign.gkey = la.eme_gkey
    * AND asign.active='X'
    * AND sa.lea_gkey = le.gkey
    * AND sa.lea_gkey = la.lea_gkey
    * AND le.city = ct.gkey(+)
    * AND le.gkey = cn.lea_gkey(+)
    * AND le.gkey = targets.lea_gkey(+)
    * AND le.gkey = top5.lea_gkey(+)
    * AND le.gkey = top100.lea_gkey(+)
    * {sql: assigneeClause}
    * UNION
    * SELECT DISTINCT la.lea_gkey,la.eme_gkey
    * FROM (SELECT gkey, name, role FROM employees WHERE {sql:fn in(gkey,{emeGkeyArray})}) e,
    * lead_assignees la,
    * shared_accounts sa,
    * leads le,
    * cities ct,
    * (select lea_gkey,name,email,phone,title from contacts where principal = 'X') cn,
    * (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TARGET') targets,
    * (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TOP5') top5,
    * (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TOP100') top100
    * WHERE e.gkey = la.eme_gkey
    * AND sa.lea_gkey = le.gkey
    * AND sa.lea_gkey = la.lea_gkey
    * AND le.city = ct.gkey(+)
    * AND le.gkey = cn.lea_gkey(+)
    * AND le.gkey = targets.lea_gkey(+)
    * AND le.gkey = top5.lea_gkey(+)
    * AND le.gkey = top100.lea_gkey(+)
    * {sql: sharedClause})::
    @JdbcControl.SQL(arrayMaxLength = 0,
    maxRows = JdbcControl.MAXROWS_ALL,
    statement = "select COUNT(*) FROM ( SELECT la.lea_gkey,la.eme_gkey FROM (SELECT gkey, name, role FROM employees WHERE {sql:fn in(gkey,{emeGkeyArray})}) e, lead_assignees la, leads le, cities ct, (select lea_gkey,name,email,phone,title from contacts where principal = 'X') cn, (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TARGET') targets, (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TOP5') top5, (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TOP100') top100 WHERE e.gkey = la.eme_gkey AND la.lea_gkey = le.gkey AND le.city = ct.gkey(+) AND le.gkey = cn.lea_gkey(+) AND le.gkey = targets.lea_gkey(+) AND le.gkey = top5.lea_gkey(+) AND le.gkey = top100.lea_gkey(+) {sql: whereClause} UNION SELECT DISTINCT la.lea_gkey,la.eme_gkey FROM (SELECT gkey, name, role FROM employees WHERE {sql:fn in(gkey,{emeGkeyArray})}) e, lead_assignees la, shared_accounts sa, leads le, cities ct, employees asign, (select lea_gkey,name,email,phone,title from contacts where principal = 'X') cn, (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TARGET') targets, (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TOP5') top5, (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TOP100') top100 WHERE e.gkey = sa.eme_gkey AND asign.gkey = la.eme_gkey AND asign.active='X' AND sa.lea_gkey = le.gkey AND sa.lea_gkey = la.lea_gkey AND le.city = ct.gkey(+) AND le.gkey = cn.lea_gkey(+) AND le.gkey = targets.lea_gkey(+) AND le.gkey = top5.lea_gkey(+) AND le.gkey = top100.lea_gkey(+) {sql: assigneeClause} UNION SELECT DISTINCT la.lea_gkey,la.eme_gkey FROM (SELECT gkey, name, role FROM employees WHERE {sql:fn in(gkey,{emeGkeyArray})}) e, lead_assignees la, shared_accounts sa, leads le, cities ct, (select lea_gkey,name,email,phone,title from contacts where principal = 'X') cn, (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TARGET') targets, (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TOP5') top5, (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TOP100') top100 WHERE e.gkey = la.eme_gkey AND sa.lea_gkey = le.gkey AND sa.lea_gkey = la.lea_gkey AND le.city = ct.gkey(+) AND le.gkey = cn.lea_gkey(+) AND le.gkey = targets.lea_gkey(+) AND le.gkey = top5.lea_gkey(+) AND le.gkey = top100.lea_gkey(+) {sql: sharedClause})")
    public Long getProspectsCount(String[] emeGkeyArray, String whereClause, String assigneeClause, String sharedClause) throws SQLException;
    The execution of the method is the following:
    pendingApprovals = leadsListingDB.getProspectsCount(employeeHierarchyArray, pendingApprovalsClause, pendingApprovalsClause, pendingApprovalsClause);
    When the method is executed all the String parameters (whereClause, assigneeClause & sharedClause) are replaced well except the array parameter (emeGkeyArray) so the execution throws the following exception because the array is not replaced:
    <Jan 20, 2010 1:01:26 PM CST> <Debug> <org.apache.beehive.controls.system.jdbc.JdbcControlImpl> <BEA-000000> <Enter: onAquire()>
    <Jan 20, 2010 1:01:26 PM CST> <Debug> <org.apache.beehive.controls.system.jdbc.JdbcControlImpl> <BEA-000000> <Enter: invoke()>
    <Jan 20, 2010 1:01:26 PM CST> <Info> <org.apache.beehive.controls.system.jdbc.JdbcControlImpl> <BEA-000000> <PreparedStatement: select COUNT(*) FROM ( SELECT la.lea_gkey,la.eme_gkey FROM (SELECT gkey, n
    me, role FROM employees WHERE (gkey IN ())) e, lead_assignees la, leads le, cities ct, (select lea_gkey,name,email,phone,title from contacts where principal = 'X') cn, (SELECT lea_gkey, tag FROM lead
    tags WHERE tag = 'TARGET') targets, (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TOP5') top5, (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TOP100') top100 WHERE e.gkey = la.eme_gkey AND la.l
    a_gkey = le.gkey AND le.city = ct.gkey(+) AND le.gkey = cn.lea_gkey(+) AND le.gkey = targets.lea_gkey(+) AND le.gkey = top5.lea_gkey(+) AND le.gkey = top100.lea_gkey(+) AND LA.ACTIVE = 'X' AND LE.WE
    KLY_POTENTIAL > 0 AND (LE.APPROVED IS NULL OR LE.APPROVED != 'Y') AND LA.SALE_STAGE IN(3034,3005) UNION SELECT DISTINCT la.lea_gkey,la.eme_gkey FROM (SELECT gkey, name, role FROM employees WHERE (gkey I
    ())) e, lead_assignees la, shared_accounts sa, leads le, cities ct, employees asign, (select lea_gkey,name,email,phone,title from contacts where principal = 'X') cn, (SELECT lea_gkey, tag FROM lea
    tags WHERE tag = 'TARGET') targets,  (SELECT leagkey, tag FROM lead_tags WHERE tag = 'TOP5') top5, (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TOP100') top100 WHERE e.gkey = sa.eme_gkey AND asi
    n.gkey = la.eme_gkey AND asign.active='X' AND sa.lea_gkey = le.gkey AND sa.lea_gkey = la.lea_gkey AND le.city = ct.gkey(+) AND le.gkey = cn.lea_gkey(+) AND le.gkey = targets.lea_gkey(+) AND le.gkey
    = top5.lea_gkey(+) AND le.gkey = top100.lea_gkey(+) AND LA.ACTIVE = 'X' AND LE.WEEKLY_POTENTIAL > 0 AND (LE.APPROVED IS NULL OR LE.APPROVED != 'Y') AND LA.SALE_STAGE IN(3034,3005) UNION SELECT DISTINCT
    la.lea_gkey,la.eme_gkey FROM (SELECT gkey, name, role FROM employees WHERE (gkey IN ())) e, lead_assignees la, shared_accounts sa, leads le, cities ct, (select lea_gkey,name,email,phone,title from c
    ntacts where principal = 'X') cn, (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TARGET') targets, (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TOP5') top5, (SELECT lea_gkey, tag FROM lead_tags
    WHERE tag = 'TOP100') top100 WHERE e.gkey = la.eme_gkey AND sa.lea_gkey = le.gkey AND sa.lea_gkey = la.lea_gkey AND le.city = ct.gkey(+) AND le.gkey = cn.lea_gkey(+) AND le.gkey = targets.lea_gkey(+
    AND le.gkey = top5.lea_gkey(+) AND le.gkey = top100.lea_gkey(+) AND LA.ACTIVE = 'X' AND LE.WEEKLY_POTENTIAL > 0 AND (LE.APPROVED IS NULL OR LE.APPROVED != 'Y') AND LA.SALE_STAGE IN(3034,3005)) Params:
    {}>
    <Jan 20, 2010 1:01:26 PM CST> <Debug> <org.apache.beehive.netui.pageflow.FlowController> <BEA-000000> <Invoking exception handler method handleException(java.lang.Exception, ...)>
    [LeadsMailer] Unhandled exception caught in Global.app:
    java.sql.SQLSyntaxErrorException: ORA-00936: missing expression
    So the big question is if that behavior is due to a bug of I'm doing something wrong. Do someone can give me an advice about this problem because the array parameter has no problems in workshop 8.1?
    Thanks in advance!

    Greetings
    I may not have an answer for you, but i am in the same boat! I am trying to pass an array to store in the database. I have 2 out of 8 columns that need to be stored as arrays. Everything saves EXEPT for the 2 arrays in question. I am using BEEHIVE with my web app. The strange thing is that i do not receive any syntax errors or runtime codes. I am still searching for an answer. If i find anything out, i will let you know.
    John Miller
    [email protected]

  • In Trouble with the Oracle JDBC Driver version - 10.1.0.5.0

    Hi !
    Without any problems i'm using the Oracle JDBC Driver version - 10.1.0.3.0 to access to the
    Oracle database (Oracle Database 10g Release 10.2.0.1.0 - 64bit Production).
    But exchanging the JDBC Driver 10.1.0.3.0 to 10.1.0.5.0 brings up the following problem:
    the statement
         con.prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability)
         (with parameters resultSetType = 1003, resultSetConcurrency = 1007, resultSetHoldability= 1)
    returns null !
    while using the Oracle JDBC Driver version - 10.1.0.3.0 the statement (with same parameters)
    returns a correct PreparedStatement.
    Every hint or idea is welcome.
    Best regards,
    Claus

    Duplicate post:
    In Trouble with the Oracle JDBC Driver version - 10.1.0.5.0
    Claus,
    Pardon me if I am stating the obvious, but why don't you use the 10.2 JDBC driver with your 10.2 database? The driver is part of the database distribution. Otherwise, you can download the driver from the OTN Web site.
    Good Luck,
    Avi.

  • Trouble accessing the database

    Hi, am new to java and I am having trouble accessing my database. I have the following code
    import java.sql.Connection;
    import java.sql.Driver;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.CallableStatement;
    import java.sql.ResultSet;
    private static boolean verifyInDB(String username, String password){
    boolean allow = false;
    try {
    Driver d =(Driver)Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
    conn = DriverManager.getConnection("jdbc:odbc:SITSDB");
    queryStr = "SELECT username,\"password\" FROM WebAppUsers WHERE username=" + "'" + username + "'" + "AND password=" + "'"+ password + "'" + "AND archive = 'no'";
    myQuery = conn.prepareCall(queryStr);
    //myQuery.setString(1, username);
    //myQuery.setString(2, password);
    rs = myQuery.executeQuery();
    if(rs.next())
    allow = true;
    catch (Exception e) {
    System.out.println("Login::verifyInDB: Error Getting Connection: " + e.toString());
    System.out.println("Login::verifyInDB: QUERY: " + queryStr);
    e.printStackTrace();
    finally{closeConn();}
    return allow;
    I'm almost positive the code it is right however I get an error trying to connect to the database
    Login::verifyInDB: Error Getting Connection: java.sql.SQLException: [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid object name 'WebAppUsers'.
    Login::verifyInDB: QUERY: SELECT username,"password" FROM WebAppUsers WHERE username='akabeera'AND password='avenash'AND archive = 'no'
    java.sql.SQLException: [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid object name 'WebAppUsers'.
    at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6958)
    at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7115)
    at sun.jdbc.odbc.JdbcOdbc.SQLExecute(JdbcOdbc.java:3150)
    at sun.jdbc.odbc.JdbcOdbcPreparedStatement.execute( JdbcOdbcPreparedStatement.java:214)
    at sun.jdbc.odbc.JdbcOdbcPreparedStatement.executeQuery( JdbcOdbcPreparedStatement.java:89)
    at com.siac.ManagementReports.Login.verifyInDB(Login.java:43)
    at com.siac.ManagementReports.Login.verify(Login.java:27)
    at org.apache.jsp.doLogin_jsp._jspService(doLogin_jsp.java:60)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
    any suggestions is much appreciated
    Message was edited by:
    ssj_100

    To be clear when you say the command works in query analyzer. Is this the exact string that you are running in query analyzer?
    SELECT username,"password" FROM WebAppUsers WHERE username='akabeera'AND password='avenash'AND archive = 'no'This exact string (the SELECT) looks syntactically incorrect to me, but that doesn't mean your database SQL parser cannot handle it I guess (lack of spaces between quotes keywords), and I'm not sure about the double quotes, but I'm kind of an Oracle guy and all of this could be OK, it just seems messy if nothing else.
    I would recommend using first, a type 4 driver if at all possible (not the JDBC/ODBC bridge), and second To avoid much of this messiness, you should whenever possible use a PreparedStatement rather then Statement for this type (and most types) of queries.

  • Trouble shooting while connecting Ms SQL Server 2008

    hi everyone i ve a trouble shooting while connecting to sql server. my whole sql connection code is here. i m using windows 7 64bit. i ve download jdk for 64bit and download jdbc driver too. in the jdbc driver folder i ve copied sqljdbc.jar file in to C:\Program Files\Java\jre6\lib\ext then i ve copied to C:\Program Files\Java\jdk1.6.0_19\jre\lib\ext then C:\Program Files (x86)\Java\jre6\lib\ext. i m not sure to where to copy. also finally i ve copied sqljdbc_auth.dll file in to C:\Windows\System32. there r two sqljdbc_auth.dll files one is 32bit other one is 64bit i checked to c folder and i see there r two microsoft sql server folders one is under program files one is under programfiles(x86). i just copied sqljdbc_auth.dll 64bit version in to system32 folder. i just found these infos from internet. i m new in java. when i run the program i get an error message which is :
    java.sql.SQLException: No suitable driver found for JDBC:sqlserver://localhost;java_data
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at ClientQuery.<init>(ClientQuery.java:31)
    at TicketSale.<init>(TicketSale.java:68)
    at TicketSale.main(TicketSale.java:409)
    the name of the database i want to connect is java_data which i made in sql server. can anyone tell me where did i made wrong?
      import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.List; import java.util.ArrayList; public class ClientQuery {    // class begin private static final String URL ="JDBC:sqlserver://localhost;java_data"; private static final String USERNAME ="root"; private static final String PASSWORD = " "; private Connection connection = null; private PreparedStatement selectAllClient = null; private PreparedStatement selectClientbyAirline = null; private PreparedStatement insertNewClient = null; // person query constructor begin public ClientQuery (){ try { try { Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); } catch (ClassNotFoundException e) { e.printStackTrace(); } connection = DriverManager.getConnection( URL, USERNAME, PASSWORD ); selectAllClient = connection.prepareStatement("SELECT * FROM Ticket"); selectClientbyAirline = connection.prepareStatement("SELECT * FROM Ticket WHERE airline = ?"); insertNewClient = connection.prepareStatement("INSERT INTO Ticket "+ "(name,surname,airline,flight_no,departure_date,departure_city,arrival_city,departure_time,arrival_time,gate,price)" + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); } // end try catch (SQLException sqlException) { sqlException.printStackTrace(); System.exit(1); } // end catch }  // person query constructor end // select all client in database public List <Client> getAllClient() { List<Client> results = null; ResultSet resultSet = null; try { resultSet = selectAllClient.executeQuery(); results = new ArrayList<Client>(); while (resultSet.next()) { results.add(new Client(     resultSet.getString("name"),     resultSet.getString("surname"),     resultSet.getString("airline"),     resultSet.getString("flight_no"),     resultSet.getString("departure_date"),     resultSet.getString("departure_city"),     resultSet.getString("arrival_city"),     resultSet.getString("departure_time"),     resultSet.getString("arrival_time"),     resultSet.getString("gate"),     resultSet.getString("price"))); }  // end while }  // end try catch (SQLException sqlException ) { sqlException.printStackTrace(); }  // end catch finally { try{ resultSet.close(); } // end try catch (SQLException sqlException) { sqlException.printStackTrace(); close(); }  // end catch }  //end finally return results; } // end of get all client method // select Client by Airline public List <Client> getClientbyAirline(String name ) { List<Client> results = null; ResultSet resultSet = null; try {             selectClientbyAirline.setString(1, name);              resultSet = selectClientbyAirline.executeQuery();             results = new ArrayList<Client>();                         while (resultSet.next()) { results.add(new Client(     resultSet.getString("name"),     resultSet.getString("surname"),     resultSet.getString("airline"),     resultSet.getString("flight_no"),     resultSet.getString("departure_date"),     resultSet.getString("departure_city"),     resultSet.getString("arrival_city"),     resultSet.getString("departure_time"),     resultSet.getString("arrival_time"),     resultSet.getString("gate"),     resultSet.getString("price"))); }  // end while     } // end try catch (SQLException sqlException) { sqlException.printStackTrace(); }  // end catch finally { try{ resultSet.close(); } // end try catch (SQLException sqlException) { sqlException.printStackTrace(); close(); }  // end catch }  //end finally return results; }    // end of select by airline method public int addClient(String name, String surname, String airline, String flight_no, String departure_date, String departure_city, String arrival_city, String departure_time, String arrival_time, String gate, String price) { int result = 0; try { insertNewClient.setString(1, name); insertNewClient.setString(2, surname); insertNewClient.setString(3, airline); insertNewClient.setString(4, flight_no); insertNewClient.setString(5, departure_date); insertNewClient.setString(6, departure_city); insertNewClient.setString(7, arrival_city); insertNewClient.setString(8, departure_time); insertNewClient.setString(9, arrival_time); insertNewClient.setString(10, gate); insertNewClient.setString(11, price); result = insertNewClient.executeUpdate(); }  // end try catch (SQLException sqlException) { sqlException.printStackTrace(); close(); }  // end catch return result; } // end of add Client method public void close () { try { connection.close(); }  // end try catch (SQLException sqlException) { sqlException.printStackTrace(); }  // end catch }  // end close method } // class end  

    Your URL string is, apparantly, incorrect. See the driver documentation.

  • Null in PreparedStatement update

    I am having trouble updateing values with a PreparedStatement when I use null as a value for one of the parameters. Example:
    String sql = "UPDATE MYTABLE SET MYFIELD = ? WHERE MYKEY = ?";
    PreparedStatement query = myConnection.prepareStatement(sql);
    query.setString(1, null);
    query.setString(2, "KEYVALUE");
    query.executeUpdate();
    This always results in the following error:
    java.sql.SQLException: Missing IN or OUT parameter at index:: 1
         at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:187)
         at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:229)
         at oracle.jdbc.driver.OracleStatement.checkBindsInAndOut(OracleStatement.java:1876)
         at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2476)
         at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:452)
    Is there another way to update something with a null value using a prepared statement?

    Use
    query.setNull(1,oracle.jdbc.OracleTypes.VARCHAR);
    instead of query.setString(1, null);No, I tried that and it does not work either. The only time I am able to use nulls for the values in a prepared statement is if it is an insert statement. It does not seem to be possible with an update. Could someone verify that this is true?

  • Trouble with SQL Statements

    Hello all that can help,
    i am programming in Ready to Program to connect to a VideoShop database using SQL statements.
    I am having trouble when using single and double inverted commas. eg vs.updateRentTable ("DELETE FROM RentTable WHERE CustId=);
    but instead of specifiying the CustId i want to make it a variable id so that i can delete any name i want according to their ID.
    also i am wondering if it is possible to write data from a database into a text file? is it possible to use Printwriter?
    Looking forward to your help,
    Manuking16

    Hi Manuking_16,
    Your question should be posted on a sql forum, not on a JDBC forum. Anyway. Just looking for answers, right?
    1) If your datatype is INT, you do not use either quotes " or single quotes in your SQL statement
    DELETE FROM RentTable WHERE CustId= 12345.
    To build the SQL String in JAVA just write:
    {code}String sqlStatement = "DELETE FROM RentTable WHERE CustId = " + custID; // custID will be casted to String.{code}
    2) Use preparedStatement
    {code}PreparedStatement pStm = conn.prepareStatement(�DELETE FROM RentTable WHERE CustId = ?");
    pStm.setInt(1, customerID);
    int numberOfDeletedLines = pStm.execute();3) If you want to enter the real name to do the deletion
    DELETE FROM RentTable WHERE CustId IN (select custID FROM Customer WHERE name = "joe bob johnson")
        To build the SQL String in JAVA just write: String sqlStatement = "DELETE FROM RentTable WHERE CustId IN (select custID FROM Customer WHERE name = '" + sCustomerName + "' )"; // just copy & pasteHope I got your question right.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Mysql PreparedStatement problem

    Hi
    I am having trouble updating a database with PreparedStatement. I am using two place holders one of theme which is a String (descr) fails to update.
    I am using
    Connector/J 3.1.13 with mysql 1.4
    here is my code
                        PreparedStatement pstmt = PrimaryConWrapper.getConnection().prepareStatement("INSERT INTO INVOICE_ENTRYES(i_id,descr,value,ts) VALUES("+id+",?,?,0)");
                        for(String eDescr:inve.keySet()){
                            pstmt.clearParameters();
                            int val = inve.get(eDescr);
                            pstmt.setString(1,eDescr);
                            pstmt.setInt(2,val);
                            int rts = pstmt.executeUpdate();
                            assert (rts==2):"In valid number of records updated "+rts;
                        }and I am getting an AssertionError
    Exception in thread "main" java.lang.AssertionError: In valid number of records updated 1
    and my daya base looks like this
    mysql> SELECT * FROM INVOICE_ENTRYES;
    +----+------+-------+------------+---------------------+
    | id | i_id | descr | value      | ts                  |
    +----+------+-------+------------+---------------------+
    | 33 |   13 |       |   50396417 | 0000-00-00 00:00:00 |
    | 34 |   13 |       | 1969358848 | 0000-00-00 00:00:00 |
    | 35 |   13 |       | 1750080256 | 0000-00-00 00:00:00 |
    | 36 |   13 |       | 1868762368 | 0000-00-00 00:00:00 |
    +----+------+-------+------------+---------------------+

    I cannot close the connection in my code because the connection is universal per login. How ever I tried you solution and I get this exception. I am not sure why this is but it could be because of the timestamp value.
                private int add(Invoice in)throws UnknownTypeException,DataSourceException,TypeMismatchException{
                    Connection con = null;
                    try{
                    if(checkName(in))throw new TypeMismatchException("Invoice "+in.getName()+" already exists");
                        String name = in.getName();
                        String descr = in.getDescr();
                        Date date = in.getDate();
                        //invlice entry map
                        Map<String,Integer> inve = in.getEntries();
                        int spId = in.getParent().getId();
                        int jobId = in.getJobMeta().getId();
                        Statement stmt = PrimaryConWrapper.getConnection().createStatement(
                                ResultSet.TYPE_FORWARD_ONLY,ResultSet.CONCUR_UPDATABLE);
                        stmt.executeUpdate("INSERT INTO INVOICES(dt,name,descr,sp_id,j_id,ts) VALUES('"+date+"','"+name+"','"+descr+"',"+spId+
                                ","+jobId+",0)",Statement.RETURN_GENERATED_KEYS);
                        ResultSet rs = stmt.getGeneratedKeys();
                        boolean chk = rs.next();
                        assert chk :"no keys returned";
                        int id = rs.getInt(1);
                        assert !rs.next():"morethan one key returned";
                        rs.close();
                        stmt.close();
                        con = PrimaryConWrapper.getConnection();
                        con.setAutoCommit(false);
                        PreparedStatement pstmt = PrimaryConWrapper.getConnection().prepareStatement("INSERT INTO INVOICE_ENTRYES(i_id,descr,value,ts) VALUES(?,?,?,?)");
                        for(String eDescr:inve.keySet()){
                            pstmt.clearParameters();
                            int val = inve.get(eDescr);
                            pstmt.setInt(1,id);
                            pstmt.setString(2,eDescr);
                            pstmt.setInt(3,val);
                            pstmt.setInt(4,0);
                            System.out.println(eDescr+","+val);
                            int rts = pstmt.executeUpdate();
                            assert (rts==1):"In valid number of records updated "+rts;
                        con.commit();
                        pstmt.close();
                        return id;
                    catch(SQLException sqle){
                        try{if(con!=null)con.rollback();}catch(Exception e){}
                        throw new DataSourceException("could not add Invoice",sqle);
                    finally{
                        try{if(con!=null)con.setAutoCommit(true);}catch(Exception e){}
                }and the exception is
    Caused by: java.sql.SQLException: Incorrect arguments to mysql_stmt_execute

  • PreparedStatement use, null check

    I'm using PreparedStatements in a number of queries that probably don't benefit from it and wondering if the problems I'm having are worth the extra I/O efficiency and security benefits. Thoughts?
    Additionally, I'm having trouble knowing for sure if my resultsets from a PS are empty. Here's some sample code:
    string sql = "SELECT * FROM atable WHERE id = ?";
    PreparedStatement ps = c.prepareStatement(sql);
    ps.setString(1, ID);
    ResultSet rs = ps.executeQuery();
    if(rs == null)
    rs.next();
    x = rs.getString("acolumn");
    I know rs.next() executes because of some debug statements I've worked into the real code, but at getString("acolumn") I get "Exhausted Resultset." When I run the query by hand, it's an empty result. So what should I be using to check for null or 0 row count?

    I'm using PreparedStatements in a number of queries
    that probably don't benefit from it and wondering if
    the problems I'm having are worth the extra I/O
    efficiency and security benefits. Thoughts?
    Additionally, I'm having trouble knowing for sure if
    my resultsets from a PS are empty. Here's some
    sample code:
    string sql = "SELECT * FROM atable WHERE id = ?";
    PreparedStatement ps = c.prepareStatement(sql);
    ps.setString(1, ID);
    ResultSet rs = ps.executeQuery();
    if(rs == null)
    rs.next();
    x = rs.getString("acolumn");
    I know rs.next() executes because of some debug
    statements I've worked into the real code, but at
    getString("acolumn") I get "Exhausted Resultset."
    When I run the query by hand, it's an empty result.
    . So what should I be using to check for null or 0
    row count?Hi,
    Your code should read:
    ResultSet rs = ps.executeQuery();
    if (rs.next()) {
        // do whatever
    }next returns a boolean that says if there was a next or not.
    /Kaj

  • JavaMail troubles with

    I'm still facing troubles with my javamail combination. the reason is that I want to send data which should be select from my sql database....
    at the moment my main problem is that I do not know how to combine my code fragments....
    here is my mailbean for sending javamail
    package coreservlets;
    import java.util.*;
    import javax.mail.*;
    import javax.mail.internet.*;
    public class MailBean {
         public String sendMail() {
              Properties props = new Properties();
                props.put("mail.smtp.host", "mail.xxx.com");
                Session s = Session.getInstance(props,null);
                MimeMessage message = new MimeMessage(s);
                InternetAddress from = null;
              try {
                   from = new InternetAddress("[email protected]");
              } catch (AddressException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
                try {
                   message.setFrom(from);
              } catch (MessagingException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
                InternetAddress to = null;
              try {
                   to = new InternetAddress("[email protected]");
              } catch (AddressException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
                try {
                   message.addRecipient(Message.RecipientType.TO, to);
              } catch (MessagingException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
                try {
                   message.setSubject("something");
              } catch (MessagingException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
                try {
                   message.setText("MESSAGE SHOULD BE DATA SELECTED FROM DATABASE");
              } catch (MessagingException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
                try {
                   Transport.send(message);
              } catch (MessagingException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
              return ("mailsuccess");}
    }but this code fragment does not send the data from the database... so I wrote another method for selecting data from mysql:
         public String SelectMail() {
             try {
                 Class.forName( "com.mysql.jdbc.Driver" ); //( "org.gjt.mm.mysql.Driver");
                 Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/imac", "user", "password");
                 try {
                      PreparedStatement ps = con.prepareStatement("SELECT (firstname, lastname, companyname, brench, email) FROM table;");
                      ps.setObject(1, firstname);
                      ps.setObject(2, lastname);
                      ps.setObject(3, companyname);
                      ps.setObject(4, brench);
                      ps.setObject(5, email);
                      ps.executeUpdate();
                 } finally {
                     con.close();
             } catch (ClassNotFoundException e) {
                  // TODO: handle exception here
                  return null;  // stay on the same page
             } catch (SQLException e) {
                  // TODO: handle exception here
                  return null;  // stay on the same page
            return("mailsuccess");  // or whatever for Navigation
         }I'm sorry but i really do not know how to combine them... shall i put them together into one method?
    or is it necessary to call up one method by the other.....
    please, please help me

    I really do my best but I'm completely confused now....
    I tried to do the following.. but the problem ist the return(ps); is not a string which is expected :(
    I really need your help...
    package coreservlets;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.SQLException;
    import java.util.*;
    import javax.mail.*;
    import javax.mail.internet.*;
    public class MailBean {
         public String sendMail() {
              Properties props = new Properties();
                props.put("mail.smtp.host", "xxx.xx");
                Session s = Session.getInstance(props,null);
                MimeMessage message = new MimeMessage(s);
                InternetAddress from = null;
              try {
                   from = new InternetAddress("[email protected]");
              } catch (AddressException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
                try {
                   message.setFrom(from);
              } catch (MessagingException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
                InternetAddress to = null;
              try {
                   to = new InternetAddress("[email protected]");
              } catch (AddressException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
                try {
                   message.addRecipient(Message.RecipientType.TO, to);
              } catch (MessagingException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
                try {
                   message.setSubject("Questionnaire - Answers");
              } catch (MessagingException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
                try {
                   message.setText(SelectMail());
              } catch (MessagingException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
                try {
                   Transport.send(message);
              } catch (MessagingException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
              return ("mailsuccess");
         public PreparedStatement SelectMail() {
             try {
                 Class.forName( "com.mysql.jdbc.Driver" ); //( "org.gjt.mm.mysql.Driver");
                 Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/imac", "user", "password");
                 try {
                      PreparedStatement ps = con.prepareStatement("SELECT * FROM questionnaire;");
                      ps.executeUpdate();
                     return ps;
                 } finally {
                     con.close();
             } catch (ClassNotFoundException e) {
                  // TODO: handle exception here
                  return null;  // stay on the same page
             } catch (SQLException e) {
                  // TODO: handle exception here
                  return null;  // stay on the same page
    }thanks a lot!!!

Maybe you are looking for

  • Error while applying OLAP patch 3140662

    Hi all, i have successfully applied Oracle OLAP Patch 3084634 [ 9.2.0.4 ONE-OFF PATCH AND 9.2.0.4.1 SERVER PATCH FOR OLAP] After that i tried to apply Oracle OLAP Patch 3140662 [Patch UNABLE TO CONNECT TO RDBMS using OLAP API] when i follow the steps

  • Time Machine: setting-up external hard drive question

    I purchased the Lacie 2TB External Hard Drive from Apple and in the set-up process it said to free up all 2 TB storage space if I intend to use it only for my MAC (which I do), so that's what I did. However, when I was doing that, the set-up screen k

  • "Error: Out of memory" [not able to open timeline or videos in 'Viewer']

    Hello all, I am opening an old project from FCP 4 to Studio 1. The old system used a 'Cinewave' capture card. The new system is AJA Kona. I opened and changed timeline settings for many projects and they worked. This project the option fails. If I op

  • Hi reg reports

    hi gurus, i have encountered a sinario where i have 5 parameters and two radio buttons in list when i click on first radiobutton then 1,3,5 parameters must allow me to enter values and the other 2,4 parameters must be in display mode.when i click on

  • How do I display course and section titles?

    I am a 'vetran' Lectora and RWD uPerform developer so Captivate is relatively new to me. It seems that 'how things are done' in Captivate is very Adobe... powerful BUT relatively convoluted. It is very easy to set up the other elearning tools to auto