java.lang.ClassNotFoundException: com.mysql.jdbc.Dirver
packagetest;importjava.sql.*;publicclassJDBCTest{/***@paramargs*/publicstaticvoidmain...
package test;
import java.sql.*;
public class JDBCTest {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
//驱动程序名
String driver = "com.mysql.jdbc.Dirver";
//URL 指向要访问的数据库名info
String url = "jdbc:mysql://localhost:3306/info";
//MySQL配置时的用户名密码
String user= "root";
String passwd= "3ntv123456";
try{
//加载驱动程序
Class.forName(driver);
//连接数据库
Connection conn = DriverManager.getConnection(url,user,passwd);
if(!conn.isClosed())
System.out.println("Succeeded conneting to the Database!");
//statement用来执行SQL语句
Statement statement = conn.createStatement();
//要执行的SQl语句
String sql = "select* from student";
//结果集
ResultSet rs = statement.executeQuery(sql);
System.out.println("-------------------");
System.out.println("执行结果如下:");
System.out.println("--------------------");
System.out.println("学号"+ "\t"+"姓名");
System.out.println("----------------------");
String name = null;
while(rs.next()){
name = rs.getString("sname");
name = new String(name.getBytes("ISO-8859-1"),"GB2312");
//输出结果
System.out.println(rs.getString("sno")+"\t"+"name");
}
rs.close();
conn.close();
}catch(ClassNotFoundException e ){
// System.out.println("Soryy,can't find the Driver");
e.printStackTrace();
}catch(SQLException e){
e.printStackTrace();
}catch(Exception e){
e.printStackTrace();
}
//System.out.println("Hello World");
}
} 展开
import java.sql.*;
public class JDBCTest {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
//驱动程序名
String driver = "com.mysql.jdbc.Dirver";
//URL 指向要访问的数据库名info
String url = "jdbc:mysql://localhost:3306/info";
//MySQL配置时的用户名密码
String user= "root";
String passwd= "3ntv123456";
try{
//加载驱动程序
Class.forName(driver);
//连接数据库
Connection conn = DriverManager.getConnection(url,user,passwd);
if(!conn.isClosed())
System.out.println("Succeeded conneting to the Database!");
//statement用来执行SQL语句
Statement statement = conn.createStatement();
//要执行的SQl语句
String sql = "select* from student";
//结果集
ResultSet rs = statement.executeQuery(sql);
System.out.println("-------------------");
System.out.println("执行结果如下:");
System.out.println("--------------------");
System.out.println("学号"+ "\t"+"姓名");
System.out.println("----------------------");
String name = null;
while(rs.next()){
name = rs.getString("sname");
name = new String(name.getBytes("ISO-8859-1"),"GB2312");
//输出结果
System.out.println(rs.getString("sno")+"\t"+"name");
}
rs.close();
conn.close();
}catch(ClassNotFoundException e ){
// System.out.println("Soryy,can't find the Driver");
e.printStackTrace();
}catch(SQLException e){
e.printStackTrace();
}catch(Exception e){
e.printStackTrace();
}
//System.out.println("Hello World");
}
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询