java连oracle,可以连入,但插入数据无法成功
package Ceshi;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class Ceshi {
private static Statement dbstate;
private Connection conn;
public Ceshi ()
{
dbstate=null;
conn = null;
}
public Connection Conn1()
{
Connection conn = null;
try {
try {
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String url="jdbc:oracle:thin:@localhost:1521:orcl"; //orcl为数据库的SID
String user="system";
String password="orcl123";
conn= DriverManager.getConnection(url,user,password);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return conn;
}
public boolean dbInsert(String name,String type,String data,String time,String intro1,String intro2)
{
/**
** 对数据库表进行插入操作
* * @param hm
* * @return bool值,成功返回true,失败返回false
* */
String CNAMEstr=name;
String CTYPEstr=type;
String CDATAstr=data;
String CTIMEstr=time;
String USER_INTRO1str=intro1;
String USER_INTRO2str=intro2;
Conn1();
String sql = "";
boolean insertResult = false;
sql += "insert into CHAT values" + "(" + "chat_seq.nextval"+",'"+ CNAMEstr+"','"+CTYPEstr+"','"+CDATAstr+"','"+CTIMEstr+"','"+USER_INTRO1str+"','"+USER_INTRO2str+"')";
try
{
dbstate.executeUpdate(sql);
System.out.println("Sql1 = " + sql);
insertResult = true;
System.out.println("Sql2 = " + sql);
}
catch(Exception e)
{
System.out.println("Sql3= " + sql);
}
if (insertResult)
return true;
else
return false;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Ceshi obj=new Ceshi();
Connection con=obj.Conn1();
if(con==null)
System.out.print("连接失败");
else
System.out.print("连接成功");
boolean in = obj.dbInsert("服务器","123","123","123",null,null); //—>>>插入
if (in)
System.out.println("insert OK" );
else