packageDriver;importjava.sql.*;publicclasssqlDriver{StringdriverName="com.microsoft.sqlserver.jdbc.SQLServerDriver";StringdriverURL="jdbc:sqlserver://localhost:1433;Dateb...
package Driver;
import java.sql.*;
public class sqlDriver {
String driverName="com.microsoft.sqlserver.jdbc.SQLServerDriver";
String driverURL="jdbc:sqlserver://localhost:1433;DatebaseName=xuelang";
String uerName="sa";
String uerPassword="123";
Connection con=null;
ResultSet rs=null;
Statement st=null;
// public void setuerName(String uerName){
// this.uerName=uerName;
// }
// public void setuserPassword(String uerPassword){
// this.uerPassword=uerPassword;
// }
public void sqlConnection(){
try{
Class.forName(driverName);
}catch(ClassNotFoundException e){
e.getMessage();
}
try{
con=DriverManager.getConnection(driverURL,uerName,uerPassword);
System.out.println("数据库连接成功");
}catch(SQLException e){
e.getMessage();
}
}
public ResultSet query(String sql){
try{
con.createStatement().executeQuery(sql);
}catch(SQLException e){
e.getMessage();
}
return rs;
}
public void updata()
{ String sql="insert into biao (pid,title,content)values ('6','asdasd','asdas')";
try{
con.createStatement().executeUpdate(sql);}
catch(SQLException e){
e.getMessage();
}
}
public static void main(String []args)
{
sqlDriver s= new sqlDriver();
s.sqlConnection();
s.updata();
}
} 没有提示..没有响应....请高手解决...解决追加50分
展开