各数据库连接代码
//Oracle8/8i/9i数据库(thin模式)
String url="jdbc:oracle:thin:@localhost:1521:orcl";
String user="scott";
String password="tiger";
Connection conn=DriverManager.getConnection(url,user,password);
//Sql Server7.0/2000/2005/2008数据库
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs";
String user="sa";
String password="";
Connection conn=DriverManager.getConnection(url,user,password);
//DB2数据库
String url="jdbc:db2://localhost:5000/sample";
String user="amdin"
String password=-"";
Connection conn=DriverManager.getConnection(url,user,password);
//MySQL数据库
String url="jdbc:mysql://localhost:3306/testDB?user=root&password=root&useUnicode=true&characterEncoding=gb2312";
Connection conn=DriverManager.getConnection(url);
一下是进行增删改查的mysql代码
增:insert into user//表名(***//表头) values(****//增加的数据)";
改:update user//表名 set userName//表头 ='"+field2+"//修改的数据',passwork='"+field3+"',teacherID="+Integer.parseInt(field4)+" where userID="+Integer.parseInt(field1);
删:delete from user where userID="+Integer.parseInt(field1//字符串类型的要先转换成整型的);
查:select * from userID//查询表中的某个表头 order by User//表名