myeclipse连接数据库遇到的几个问题

时间:2023-03-08 17:19:38

1:无效的SQL URL:

//将获取的参数插入数据库

   
    Connection
conn=null;

   
   
PreparedStatement stat=null;

   
    try {

   
   
   
Class.forName("oracle.jdbc.OracleDriver");

   
   
    try {

   
   
   
   
conn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl",

"system","oracle");

   
   
   
    String
sql="insert into t_emp values(t_emp_id_seq.nextval,?,?,?)";

   
   
   
   
stat=conn.prepareStatement(sql);

   
   
   
   
stat.setString(1,name);

   
   
   
   
stat.setDouble(2,salary);

   
   
   
   
stat.setInt(3,age);

   
   
   
   
stat.executeUpdate();

   
   
   
   
out.println("添加完成!");

   
   
   
   
out.close();

错误的原因:thin的后面有:  ,很容易被忽略,以后做项目要注意



2:第二个错误是java.sql.SQLException: Listener refused the connection with
the following error:

这个是sid错误的原因,本来是orcl,被我写成了xe,没有修改,使用了默认的了,以后做项目是应该留心。