Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

update my table in database doesn't work?

Status
Not open for further replies.

darine

Programmer
Jun 23, 2000
28
0
0
US
Hi all
I'm trying to be more familiar with jdbc,so i created my table and i could insert data to it and retrieve data from it. but i'm trying to update it ,for some reason i can't. here is my code,any help will be appreciated.
Thank you.
===============
import java.sql.*;
import java.net.*;
public class ConnectToDatabaseCreateTable
{

//String s;
//public String getData()
public static void main(String a[])
{

try
{
Class.forName
("sun.jdbc.odbc.JdbcOdbcDriver");
//String url = "jdbc:eek:dbc:mydatabase";
String url = "jdbc:eek:dbc:databse1";

Connection connection =
DriverManager.getConnection
(url, "", "");

Statement st=connection.createStatement
(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
//Statement st=connection.createStatement
();
/*
st.executeUpdate("CREATE TABLE COFFEES "
+
"(COF_NAME VARCHAR(32), SUP_ID
INTEGER, PRICE FLOAT, " +
"SALES INTEGER, TOTAL INTEGER)");

st.executeUpdate(
"INSERT INTO COFFEES " +
"VALUES ('Colombian', 101,
7.99, 0, 0)");
st.executeUpdate("INSERT INTO
COFFEES " +
"VALUES ('French_Roast', 49,
8.99, 0, 0)");
st.executeUpdate("INSERT INTO COFFEES " +
"VALUES ('French_Roast', 49,
8.99, 0, 0)");

*/
String updateString = "UPDATE COFFEES " +
"SET SALES = 9999 " +
"WHERE COF_NAME
LIKE 'Colombian'";
st.executeUpdate(updateString);

/*
String query = "SELECT COF_NAME, SALES FROM COFFEES " +
"WHERE COF_NAME
LIKE 'Colombian'";
ResultSet rs = st.executeQuery(query);
while (rs.next()) {
String s = rs.getString
("COF_NAME");
int n = rs.getInt
("SALES");
System.out.println(n + "
pounds of " + s +

" sold this week.");
}

*/
}
catch(ClassNotFoundException e)
{
e.printStackTrace();

}
catch (SQLException e)
{
e.printStackTrace();
}

//return "ssssssss";
}
}

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top