如何在eclipse调用已做好的sqlite3数据库
我在网上找到一些程序,已经可以在eclipse上建sqlite3的表,和显示内容了。所以应该所需的驱动都齐全了。现在想调用、显示已做好的表zidian.db(放在E盘),...
我在网上找到一些程序,已经可以在eclipse上建sqlite3的表,和显示内容了。
所以应该所需的驱动都齐全了。
现在想调用、显示已做好的表zidian.db(放在E盘),代码应该怎么写?
这也是网上找的程序,应该就是调用已做好的表,但运行后总显示:
No suitable driver found for jdbc:sqlite:e:/zidian.db
java.sql.SQLException: No suitable driver found for jdbc:sqlite:e:/zidian.db
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class SQLiteTest {
public static void main(String[] args) {
try {
String fileName = "e:/zidian.db";
Connection conn = DriverManager.getConnection("jdbc:sqlite:"+fileName);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM pmp_countries ORDER BY country_name ASC");
while (rs.next()) {
String id = rs.getString("country_id");
String code = rs.getString("country_code");
String name = rs.getString("country_name");
System.out.println("ID: "+id+" Code: "+code+" Name: "+name);
}
conn.close();
}
catch (Exception e) {
System.out.println(e.getMessage());
System.out.println(e.toString());
}
}
}
求高手指点一下~感激不尽~
还有就是如何解决中文不能显示的问题 展开
所以应该所需的驱动都齐全了。
现在想调用、显示已做好的表zidian.db(放在E盘),代码应该怎么写?
这也是网上找的程序,应该就是调用已做好的表,但运行后总显示:
No suitable driver found for jdbc:sqlite:e:/zidian.db
java.sql.SQLException: No suitable driver found for jdbc:sqlite:e:/zidian.db
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class SQLiteTest {
public static void main(String[] args) {
try {
String fileName = "e:/zidian.db";
Connection conn = DriverManager.getConnection("jdbc:sqlite:"+fileName);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM pmp_countries ORDER BY country_name ASC");
while (rs.next()) {
String id = rs.getString("country_id");
String code = rs.getString("country_code");
String name = rs.getString("country_name");
System.out.println("ID: "+id+" Code: "+code+" Name: "+name);
}
conn.close();
}
catch (Exception e) {
System.out.println(e.getMessage());
System.out.println(e.toString());
}
}
}
求高手指点一下~感激不尽~
还有就是如何解决中文不能显示的问题 展开
3个回答
展开全部
代码改成这样就可以了~~
public class SQLiteTest {
public static void main(String[] args) throws ClassNotFoundException{
Class.forName("org.sqlite.JDBC");
Connection connection = null;
try {
String fileName = "e:/zidian.db";
Connection conn = DriverManager.getConnection("jdbc:sqlite:zidian.db");
…………
…………
public class SQLiteTest {
public static void main(String[] args) throws ClassNotFoundException{
Class.forName("org.sqlite.JDBC");
Connection connection = null;
try {
String fileName = "e:/zidian.db";
Connection conn = DriverManager.getConnection("jdbc:sqlite:zidian.db");
…………
…………
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询