日期:2014-05-20 浏览次数:20970 次
开始创建表---- ..............false 开始创建表---- br.com.dreamsource.mobile.jmesql.exceptions.SQLException: already exists: PRICETABLE -- S0001 in statement [CREATE TABLE priceTable ( id int identity, name varchar(20) not null, percent float not null, primary key(id))] -- Table at br.com.dreamsource.mobile.jmesql.jdbcResultSet.<init>(+37) at br.com.dreamsource.mobile.jmesql.jdbcConnection.executeStandalone(+19) at br.com.dreamsource.mobile.jmesql.jdbcConnection.execute(+21) at br.com.dreamsource.mobile.jmesql.jdbcStatement.fetchResult(+36) at br.com.dreamsource.mobile.jmesql.jdbcStatement.execute(+5) at com.sqlplus.FrameMainMIDlet.createDatabase(+48) at com.sqlplus.FrameMainMIDlet.commandAction(+33) at javax.microedition.lcdui.Display$DisplayAccessor.commandAction(+282) at javax.microedition.lcdui.Display$DisplayManagerImpl.commandAction(+10) at com.sun.midp.lcdui.DefaultEventHandler.commandEvent(+68) at com.sun.midp.lcdui.AutomatedEventHandler.commandEvent(+47) at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.handleVmEvent(+186) at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.run(+57)
package com.sqlplus;
import java.util.Vector;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.TextField;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import br.com.dreamsource.mobile.jmesql.jdbcConnection;
import br.com.dreamsource.mobile.jmesql.jdbcDriver;
import br.com.dreamsource.mobile.jmesql.jdbcPreparedStatement;
import br.com.dreamsource.mobile.jmesql.jdbcResultSet;
import br.com.dreamsource.mobile.jmesql.jdbcStatement;
import br.com.dreamsource.mobile.jmesql.exceptions.SQLException;
public class FrameMainMIDlet extends MIDlet implements CommandListener {
private Form mainForm;
private static DatabaseManager myDatabaseManager;
private UserPOJO userPOJO;
TextField tf = new TextField("要写入的数据", "", 100, TextField.ANY);
TextField cx = new TextField("查询条件", "", 100, TextField.ANY);
TextField cxjg = new TextField("查询结果", "", 100, TextField.ANY);
Command a_cmdSet = new Command("添加", Command.SCREEN, 0);
Command w_cmdSet = new Command("修改", Command.SCREEN, 0);
Command r_cmdSet = new Command("查询", Command.SCREEN, 0);
Command c_cmdSet = new Command("创建表", Command.SCREEN, 0);
Command exitCommand = new Command("退出", Command.EXIT, 0);
public FrameMainMIDlet() {
mainForm = new Form("嵌入式数据库");
mainForm.append(tf);
mainForm.append(cx);
mainForm.append(cxjg);
mainForm.addCommand(exitCommand);
mainForm.addCommand(c_cmdSet);
mainForm.addCommand(r_cmdSet);
mainForm.addCommand(w_cmdSet);
mainForm.addCommand(a_cmdSet);
mainForm.setCommandListener(this);
}
/* *//**
* 检查数据库如果没有开始创建
*
* @return
* @throws Exception
*/
public void createDatabase(UserPOJO userPOJO) {
jdbcDriver driver = new jdbcDriver();
// String userName = userPOJO.getUserName();
// String userPassword = userPOJO.getPasswd();
userPOJO.setUserName("SA");
userPOJO.setPasswd("");
userPOJO.setDbName(Consts.DATABASE_NAME);
jdbcConnection connection;
try {
connection = driver.connect(userPOJO.getAsProperties());
jdbcStatement statement = connection.createStatement();
boolean l=statement.execute(Consts.CREATE_PRICETABLE_TBL);
System.out.println(".............."+l);
if(l==true){
tf.setString("创建表成功.........");
boolean k=statement.execute("insert into priceTable values (null, 'tabela1', 10)");
if(k==true){
cx.setString("插入数据成功.......");
try {
jdbcPreparedStatement prepared =connection.prepareStatement("select name from priceTable");
jdbcResultSet res = prepared.executeQuery();
int i;
StringBuffer Results = new StringBuffer();
this.cxjg.setString("");
System.out.println("数据查询"+Results);
if (!(res == null)) {
while (res.next()) {
for (i = 1; i <= res.getColumnCount(); i++) {
this.cxjg.setString(this.cxjg.getString()
+ res.getColumnName(i) + " -- "
+ res.getString(i) + "\n");
}
this.cxjg.setString(this.cxjg.getString());
}
}
} catch (Exception e) {
this.cxjg.setString(e.getMessage());
}
}else{
cx.setString("插入数据失败.......");
}
}else{
tf.setString("创建表失败.....");
}
// boolean i=statement.execute(Consts.CREATE_CUSTOMER_TBL);
} catch (SQLException e1) {
// TODO 自动生成 catch 块
e1.printStackTrace();
}
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
// TODO 自动生成方法存根
}
protected void pauseApp() {
// TODO 自动生成方法存根
}
protected void startApp() throws MIDletStateChangeException {
// TODO 自动生成方法存根
this.userPOJO = new UserPOJO();
this.userPOJO.setConnectionURL(Consts.DATABASE_CONNETION_STRING);
this.userPOJO.setDbName(Consts.DATABASE_NAME);
if (DatabaseManager.databaseExists(Consts.DATABASE_NAME)) {
Display.getDisplay(this).setCurrent(mainForm);
} else {
Display.getDisplay(this).setCurrent(mainForm);
}
}
public void commandAction(Command command, Displayable displayable) {
if (command == r_cmdSet) {
}else if(command==c_cmdSet){
System.out.println("开始创建表----");
try {
createDatabase( userPOJO);
} catch (Exception e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
}
}
}