java连接MYSQL找不到驱动问题,请高手帮助
程序里面提示找不到MYSQL驱动代码如下:Stringurl="jdbc:mysql://localhost:3306/t_1";Stringdriver="com.my...
程序里面提示找不到MYSQL驱动代码如下:
String url="jdbc:mysql://localhost:3306/t_1"; String driver = "com.mysql.jdbc.Driver"; String user = "root"; String password = "mysql"; try{ Class.forName("com.mysql.jdbc.Driver"); Connection conn = DriverManager.getConnection(url, user, password); if(!conn.isClosed()){ System.out.println("Succeeded connecting to the Database!"); Statement st = conn.createStatement(); String sql = "select * from t_1a"; ResultSet rs = st.executeQuery(sql); String name=rs.getString("name"); jTextField2.setText(name); String addr=rs.getString("address"); jTextField4.setText(addr); float gz=rs.getFloat("salary"); String gzc=Float.toString(gz); jTextField3.setText(gzc); String id=rs.getString("id"); jTextField3.setText(id); } }catch(ClassNotFoundException e) { System.out.println("Sorry,can`t find the Driver!"+e.toString()); } catch(SQLException e) { e.printStackTrace(); } catch(Exception e) { e.printStackTrace(); }
} 展开
String url="jdbc:mysql://localhost:3306/t_1"; String driver = "com.mysql.jdbc.Driver"; String user = "root"; String password = "mysql"; try{ Class.forName("com.mysql.jdbc.Driver"); Connection conn = DriverManager.getConnection(url, user, password); if(!conn.isClosed()){ System.out.println("Succeeded connecting to the Database!"); Statement st = conn.createStatement(); String sql = "select * from t_1a"; ResultSet rs = st.executeQuery(sql); String name=rs.getString("name"); jTextField2.setText(name); String addr=rs.getString("address"); jTextField4.setText(addr); float gz=rs.getFloat("salary"); String gzc=Float.toString(gz); jTextField3.setText(gzc); String id=rs.getString("id"); jTextField3.setText(id); } }catch(ClassNotFoundException e) { System.out.println("Sorry,can`t find the Driver!"+e.toString()); } catch(SQLException e) { e.printStackTrace(); } catch(Exception e) { e.printStackTrace(); }
} 展开
3个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询