Biblioteca Java - Rev 32
Subversion Repositories:
/*
* TestModificaTabel.java
*/
package lab.scd.db.jdbc10;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import lab.scd.db.util.DBConfig;
/**
* Class created by @author Mihai HULEA at Mar 10, 2005.
*
* This class is part of the laborator4_db project.
*
* Pentru realizarea de modificari asupra bazei de date se foloseste metoda executeUpdate()
* din cadrul clasei Statement.
*
*/
public class TestModificaTabel {
public static void main(String[] args) {
try{
//incarcare driver petru baza de date
Class.forName("com.mysql.jdbc.Driver");
//conectare la baza de date
Connection conn = DriverManager.getConnection("jdbc:mysql://"+DBConfig.HOST+"/"+DBConfig.DATABASE+"?user="+DBConfig.USER+"&password="+DBConfig.PWD);
System.out.println("Conexiune la baza de date realizata.");
//contruieste un obiect de tip statement
Statement stat = conn.createStatement();
String updateString = "UPDATE STOC "+
"SET PROD = 'prod modificat'"+
"WHERE PROD LIKE 'PRODUS A';";
//modifica inregistrarile din tabel
stat.executeUpdate(updateString);
//afiseaza datele din tabel modificate
ResultSet rs = stat.executeQuery("SELECT * FROM STOC;");
while(rs.next()){
String pname = rs.getString("PROD");
int ppret = rs.getInt("PRET");
System.out.println("Produs:"+pname+" Pret:"+ppret);
}//.while
}catch(Exception e){
e.printStackTrace();
}
}//.main
}
* TestModificaTabel.java
*/
package lab.scd.db.jdbc10;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import lab.scd.db.util.DBConfig;
/**
* Class created by @author Mihai HULEA at Mar 10, 2005.
*
* This class is part of the laborator4_db project.
*
* Pentru realizarea de modificari asupra bazei de date se foloseste metoda executeUpdate()
* din cadrul clasei Statement.
*
*/
public class TestModificaTabel {
public static void main(String[] args) {
try{
//incarcare driver petru baza de date
Class.forName("com.mysql.jdbc.Driver");
//conectare la baza de date
Connection conn = DriverManager.getConnection("jdbc:mysql://"+DBConfig.HOST+"/"+DBConfig.DATABASE+"?user="+DBConfig.USER+"&password="+DBConfig.PWD);
System.out.println("Conexiune la baza de date realizata.");
//contruieste un obiect de tip statement
Statement stat = conn.createStatement();
String updateString = "UPDATE STOC "+
"SET PROD = 'prod modificat'"+
"WHERE PROD LIKE 'PRODUS A';";
//modifica inregistrarile din tabel
stat.executeUpdate(updateString);
//afiseaza datele din tabel modificate
ResultSet rs = stat.executeQuery("SELECT * FROM STOC;");
while(rs.next()){
String pname = rs.getString("PROD");
int ppret = rs.getInt("PRET");
System.out.println("Produs:"+pname+" Pret:"+ppret);
}//.while
}catch(Exception e){
e.printStackTrace();
}
}//.main
}