packagecom.yootk.demo;importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.PreparedStatement;importjava.sql.ResultSet;importjava.util.Date;importcom.mysq...
package com.yootk.demo;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Date;
import com.mysql.cj.xdevapi.Result;
public class nothing{
private static final String DBDRIVER="com.mysql.cj.jdbc.Driver";
private static final String DBURL="jdbc:mysql://127.0.0.1:3306/test";
private static final String USER="root";
private static final String PASSWORD="111111";
public static void main(String ags[])throws Exception
{
Class.forName(DBDRIVER);
Connection conn=DriverManager.getConnection(DBDRIVER, USER, PASSWORD);
String sql="SELECT goods_id,goods_name,goods_price FROM tdb_goods Order by goods_id";
PreparedStatement a=conn.prepareStatement(sql);
ResultSet rs=a.executeQuery();
while (rs.next())
{
int good_id=rs.getInt(1);
String goods_name=rs.getString(2);
String goods_cate=rs.getString(3);
String brand_name=rs.getString(4);
int goods_price=rs.getShort(5);
int is_show =rs.getInt(6);
int is_saleoff=rs.getInt(7);
System.out.println("序号:"+good_id+" 名称:"+goods_name+" 种类:"+goods_cate+" 品牌:"+brand_name+" 价格:"
+brand_name);
conn.close();
}
}
}
代码如上。
出现的错误是
Exception in thread "main" java.sql.SQLException: No suitable driver found for com.mysql.cj.jdbc.Driver
at java.sql.DriverManager.getConnection(DriverManager.java:689)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at com.yootk.demo.nothing.main(nothing.java:16)
有没有大神解答呀~
展开