• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Example of INSERT

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I need an example where some rows are inserted in a PointBase table. The values are stored in some variables and those variables have to be passed to executeUpdate().

Any help is appreaciated.

Thanks,
Rajeev.
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

This could be achieved using Prepared Statement in JDBC API. ACtually, its no differnt from using this from any other db:

PreparedStatement ps2 = conn.prepareStatement(
"INSERT INTO TBL_NAME(COL1,COL2,COL3,COL4,COL5) "+
"VALUES(?, ?, ?, ?, ?)";
-- this sample code sets the values of dynamic parameters
-- to be the values of program variables
ps2.setInt(1, var1);
ps2.setInt(2, var2);
ps2.setDate(3, var3);
ps2.setString(4, var4);

updateCount = ps2.executeUpdate();

Incase, if you want to insert multiple rows, then you cud use batch transaction or put this in a loop..
 
Rajeev Asthana
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jyothi Lature:
Hi,

This could be achieved using Prepared Statement in JDBC API. ACtually, its no differnt from using this from any other db:

PreparedStatement ps2 = conn.prepareStatement(
"INSERT INTO TBL_NAME(COL1,COL2,COL3,COL4,COL5) "+
"VALUES(?, ?, ?, ?, ?)";
-- this sample code sets the values of dynamic parameters
-- to be the values of program variables
ps2.setInt(1, var1);
ps2.setInt(2, var2);
ps2.setDate(3, var3);
ps2.setString(4, var4);

updateCount = ps2.executeUpdate();

Incase, if you want to insert multiple rows, then you cud use batch transaction or put this in a loop..



Thanks, I tried following:

I have created a database DEV and its URL is: jdbc ointBase EV.

I then added pbembedded.jar in CLASSPATH Suffix in JVM tab in Admin Console.

I also created a JNDI entry as jdbc/dev.

Then I created a table USER_SALARY in the schema PBPUBLIC.

I want to use the table in my Session Bean to insert rows in this table.

I specified it as:

...
ds = (DataSource)ctx.lookup("jdbc/dev");
conn = ds.getConnection();
pstmt = conn.prepareStatement("INSERT INTO PBPUBLIC.USER_SALARY (USER_NAME, SALARY) VALUES(?,?)");

pstmt.setString(1, userName);
pstmt.setDouble(2, (initialSalary*1.25));


updatecount = pstmt.executeUpdate();

.....

When I run the programs, I see that there is an error message in the server.log file:
"....table USER_SALARY is not found...."

What could be the error?

Any help is appreciated.

Thanks,
Rajeev.
 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the ejb cannot find the pointbase driver
i also could not use the pointbase database as the driver is not loaded by the jdbc api.
the driver is com.pointbase.jdbc.jdbcUniversalDriver but the class is not found by the jdbc api

my sample program



the coding: -

----------------------------------------------------------------

import javax.sql.*;
import java.sql.*;
import java.util.*;
import java.lang.*;


public class con1 {
public static void main(String args[])
{
try {

Class.forName("com.pointbase.jdbc.jdbcUniversalDriver");
Connection connection =
DriverManager.getConnection("jdbc ointbase:user1",

"PBPUBLIC", "PBPUBLIC");
DatabaseMetaData meta = connection.getMetaData();
System.out.println("Database:
"+meta.getDatabaseProductName());
System.out.println(" version
"+meta.getDatabaseProductVersion());
System.out.println("User Name:
"+meta.getUserName());
connection.close();
}
catch(Exception ex) {
System.out.println(ex);
System.exit(0);
}
}
}

--------------------------------------------------------------------


but when i run the above program i get the message

java.lang.ClassNotFoundException:
com.pointbase.jdbc.jdbcUniversalDriver


thanks

Pradyut
http://pradyut.tk
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic