File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Example of INSERT Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Example of INSERT " Watch "Example of INSERT " New topic
Author

Example of INSERT

Rajeev Asthana
Ranch Hand

Joined: Oct 27, 2003
Posts: 43
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.
Jyothi Lature
Ranch Hand

Joined: Oct 31, 2001
Posts: 60
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..


Jyothi<br />Sun Certified Java Programmer<br />Brainbench Certified for Javascript
Rajeev Asthana
Ranch Hand

Joined: Oct 27, 2003
Posts: 43
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.
Pradyut Bhattacharya
Ranch Hand

Joined: Aug 12, 2004
Posts: 63
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


Pradyut
http://pradyut.tk/
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Example of INSERT