急急···关于向ACCESS插入数据的问题~~~
/**
*
*/
package bookstore;
/**
* 对数据库的操作
*
*/
import java.sql.*;
public class Database {
Connection conn=null;
//构造函数建立与数据库的连接
public Database()
{
String drivename= "sun.jdbc.odbc.JdbcOdbcDriver ";
String dsource= "jdbc:odbc:BookStore ";
try
{
Class.forName(drivename);
conn=DriverManager.getConnection(dsource);
}
catch(Exception e)
{
e.printStackTrace();
}
}
//对数据库执行查询操作
public ResultSet execQuery()
{
ResultSet rs=null;
String sql= "select * from bookuser ";
try
{
Statement sta=conn.createStatement();
rs=sta.executeQuery(sql);
rs.next();
System.out.println(rs.getString( "userid "));
}
catch(
SQLException e)
{
e.printStackTrace();
}
return rs;
}
//对数据库进行修改修改操作
public boolean execUpdate()
{
boolean flag=false;
// String sql= "insert into bookuser (userid) values( '10000 ') ";
String sql= "insert into bookuser(userid,psw,username,tel,email,address,postcode) values( '1000 ', '0001 ', '0010 ', '00100 ', '000001 ', '0000001 ', '000000001 ') ";
try
{
Statement sta=conn.createStatement();
sta.executeUpdate(sql);
flag=true;
}
catch(SQLException e)
{
e.printStackTrace();
}
return flag;
}
public static void main(String args[])
{
Database db=new Database();
boolean b=false;
b=db.execUpdate();
if(b)
{
System.out.print( "Insert ok ");
}
else
{
System.out.print( "error ");
}
}
// db.execQuery();}
}
为什么插不进去啊~~~~
唉...
实在是找不出原因了!!!
请帮帮忙啊~~···
------解决方案--------------------数据库字段都是字符型的?
------解决方案--------------------看看 e.printStackTrace();显示什么