下面这段代码为什么在windows下运行正常,在linux下就报错了?

热血大婶 热血大婶 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
以下代码的功能是向数据库里写数据,在windows下可以正常写入,在linux系统中运行就不能,并且报以下错误:
No suitable driver found for jdbc:mysql://109.105.114.137/dingheng
public class FirstJDBC {

Connection con = null;
Statement stmt = null;
String surl, suser, spsw;

FirstJDBC(String url, String user, String psw){
surl = url;
suser=user;
spsw=psw;
connectDB();
}

public void clean(){

try {
con.close();
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
}

public Statement connectDB(){
try {
con = DriverManager.getConnection(surl, suser,spsw);
stmt = con.createStatement();

return stmt;
} catch (SQLException e) {
e.printStackTrace();
}
return null;

}

public void Query(String sql){

ResultSet result = null;
try {
result = stmt.executeQuery(sql);
while(result.next()){
int id = result.getInt("id");
String ban = result.getString("name");
System.out.println(id+" "+ban);
}
if(result!=null){
result.close();
}
} catch (SQLException e) {
e.printStackTrace();
}

}

public void Insert(String sql){
try {
stmt.executeUpdate(sql);
} catch (SQLException e) {
e.printStackTrace();
}

}

public static void main(String[] args) {

FirstJDBC j = new FirstJDBC("jdbc:mysql://109.105.114.137/dingheng", "root", "");

j.Insert("insert into hetest values('linuxx','linuxx')");

j.clean();

}

}
...全文

相关推荐

评论 2
收藏 已收藏
分享
返回顶部
热血大婶
Java 51,407 成员 86,137 内容