wood burning stoves 2.0*
The moose likes JDBC and the fly likes Database Connectivity Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Database Connectivity" Watch "Database Connectivity" New topic
Author

Database Connectivity

Patrick Mugabe
Ranch Hand

Joined: Jan 08, 2002
Posts: 132
I have written a java Program that inserts data into a database.
The program is compiling and is giving no run time errors.However the problem I am facing is that when I go to the database and try to retrieve the data that I inserted through the java applet there is nothing.
I am using SQLServer 2000 as my database.
Here is a section of my code that connects to the database:
if(obj == btOK)
{
//add try and Catch Blocks for Exception Handling
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con;
//establish the connection with the data source
String url = "jdbc dbc:MyDataSource";
con = DriverManager.getConnection(url, "sa" ,"mugapatr");
//create the statement Object
PreparedStatement stat = con.prepareStatement("insert into Shopper(shopperID, firstName, lastName, emailId, address, city, state, countryId, phone, creditCardType, creditCardNo, expiryDate, pword) values(?,?,?,?,?,?,?,?,?,?,?,?,?)");
//fill up the parameter values from the controls
stat.setString(1, txtShopperID.getText());
stat.setString(2, txtFName.getText());
stat.setString(1, txtLastName.getText());
stat.setString(1, txtEmail.getText());
stat.setString(1, txtAddress.getText());
stat.setString(1, txtCity.getText());
stat.setString(1, txtState.getText());
stat.setString(1, txtCountryID.getText());
stat.setString(1, txtPhone.getText());
stat.setString(1, (String)comboCreditCardType.getSelectedItem());
stat.setString(1, txtCreditCardNo.getText());
stat.setString(1, txtExpiryDate.getText());
stat.setString(1, txtPword.getText());
//insert record into table
stat.executeUpdate();
}//end try
catch(Exception ex)
{
System.out.println("Error encountered while entering data :" + ex);
}//end catch
}//end if with try and catch block

Does anyone know what the problem could be?
Roy Ben Ami
Ranch Hand

Joined: Jan 13, 2002
Posts: 732
first im sure it a typo but u are not inserting everything in to 1 right?
u mean 1 2 3 4 5 etc... right?
secondly, make sure u close the statement and connection at the end so it will make the changes and show in your database.
Patrick Mugabe
Ranch Hand

Joined: Jan 08, 2002
Posts: 132
Thanks for your response.
I still have a question. How do I close the statement and the connection.
Roy Ben Ami
Ranch Hand

Joined: Jan 13, 2002
Posts: 732
at the end put:
stat.close();
con.close();
Patrick Mugabe
Ranch Hand

Joined: Jan 08, 2002
Posts: 132
I tried putting :
stat.close();
con.close();
at the end but still it's not working.
I am getting no results.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Database Connectivity
 
Similar Threads
JDBC-ODBC
java.sql.Date problem
Prepared Statement problem in my servlet's data manager
Syntax error in INSERT statement
java.sql.Date problem