Skip to Content
0
Former Member
Feb 12, 2007 at 03:49 PM

DB Connection - Why does not the sql statement data display?

32 Views

1. I config the data source MYSQL in visual admin successfylly.

2. I connect to MYSQL and select table data.

3. But all data is null.

My program is as the following.

Variable name1 is always null.

-


public static Connection getConnection() {

String DRIVER = "com.mysql.jdbc.Driver";

String iURL = "jdbc:mysql://ec004056:3306/demo";

String USER = "root";

String PASSWD = "123123";

try {

Class.forName(DRIVER);

} catch (ClassNotFoundException e) {

System.out.println("DB Driver Error");

e.printStackTrace();

}

Connection conn = null;

try {

conn = DriverManager.getConnection(iURL, USER, PASSWD);

} catch (SQLException e) {

e.printStackTrace();

}

return conn;

};

-


public void createBasket( )

{

//@@begin createBasket()

//sandy start

String name1;

name1=null;

int age;

age=30;

//String BASKET1[][]=null;

Connection conn = null;

Statement stmt = null;

ResultSet result=null;

int j=0;

try{

InitialContext ic = new InitialContext();

DataSource ds = (DataSource)ic.lookup("MYSQL");

conn=ds.getConnection();

//stmt = conn.prepareStatement("SELECT * FROM user");

//conn = getConnection();

//stmt = conn.createStatement();

String sql = "SELECT * FROM user";

result = stmt.executeQuery(sql);

//while (result.next())

//{

name1=result.getString(1);

// j++;

//}

}catch(Exception e){

e.printStackTrace();

}

//sandy end

for (int i = 0; i < BASKET.length ; i++)

{

IProductsElement product = wdContext.createProductsElement();

product.setARTICLE(name1);

product.setCOLOR(BASKET<i>[1]);

product.setCURRENCY("EUR");

product.setSIZE(BASKET<i>[2]);

product.setORDER_NUMBER(BASKET<i>[3]);

product.setPRICE(new BigDecimal(BASKET<i>[4]));

product.setSPECIAL_FEATURES(BASKET<i>[5]);

product.setTEXTILE_CATEGORY(BASKET<i>[6]);

wdContext.nodeProducts().addElement(product);

}

//@@end

}

-


public void wdDoInit()

{

//@@begin wdDoInit()

createBasket();

//@@end

}