日期:2014-05-18  浏览次数:20846 次

数据库的连接!!!!!!!!!!!
package   com.itjob.bookstore.dao;

import   java.beans.Statement;
import   java.sql.Connection;
import   java.sql.DriverManager;
import   java.sql.PreparedStatement;
import   java.sql.ResultSet;
import   java.sql.SQLException;


import   com.itjob.bookstore.vo.User;

public   class   UserDao   {
public   void   registerUser(User   user)   {
String   driver= "oracle.jdbc.driver.OracleDriver ";
String   url= "jdbc:oracle:thin:@192.168.0.1:1521:orcl ";
String   username= "panyu ";
String   userpwd= "panyu329 ";
Connection   conn=null;
Statement   stm=null;
ResultSet   rs=null;
try   {

Class.forName(driver);
conn   =   DriverManager.getConnection(url,   username,   userpwd);
StringBuffer   sql=new   StringBuffer();
sql.append( "insert   into   users(user_account,user_password,user_name,user_sex,user_birth, ");
sql.append( "user_tel,user_phone,user_address,user_post,user_email,user_tag)   values   ( ");
sql.append( "sql_bookstore.nextval, ");
sql.append(user.getUser_account());
sql.append( ", ");
sql.append(user.getUser_password());
sql.append( ", ");
sql.append(user.getUser_name());
sql.append( ", ");
sql.append(user.getUser_sex());
sql.append( ", ");
sql.append(user.getUser_birth());
sql.append( ", ");
sql.append(user.getUser_tel());
sql.append( ", ");
sql.append(user.getUser_phone());
sql.append( ", ");
sql.append(user.getUser_address());
sql.append( ", ");
sql.append(user.getUser_post());
sql.append( ", ");
sql.append(user.getUser_email());
sql.append( ", ");
sql.append(user.getUser_tag());
sql.append( "   ) ");

System.out.println(sql.toString());

PreparedStatement   ps=conn.prepareStatement(sql.toString());
ps.executeUpdate();

}   catch   (Exception   e)   {
e.printStackTrace();
}finally{
if(conn!=null)
try{
conn.close();
}catch(SQLException   e){
e.printStackTrace();
}
}
}
}
这个是我写的一个连接数据库的程序,可是在运行的时候提示的却是,如下信息:
insert   into   users(user_account,user_password,user_name,user_sex,user_birth,user_tel,user_phone,user_address,user_post,user_email,user_tag)   values   (sql_book.nextval,33,33,33,1,33,33,33,null,33,33,1   )
java.sql.SQLException:   ORA-00913:   值过多

at   oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at   oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)
at   oracle.jdbc.ttc7.Oall7.receive(Oall7.java:573)
at   oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1891)
at   oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java:1093)
at   oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:2047)
at   oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:1940)
at   oracle.jdbc.driver.OracleSta