java连接access数据问题
packagedb_test;importjava.sql.*;publicclassMain{publicstaticvoidmain(String[]args){Co...
package db_test;
import java.sql.*;
public class Main
{
public static void main(String[] args)
{
Connection con;
Statement sql;
ResultSet rs;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e)
{
System.out.println("建立桥接出错:");
System.out.println(e);
}
try
{
String url="jdbc:odbc:driver={Microsoft Access Driver(*.mdb)};DBQ=D:\\Tee_db\\db1.mdb";
con=DriverManager.getConnection(url,"","");
sql=con.createStatement();
rs=sql.executeQuery("select * from music");
while(rs.next())
{
String num=rs.getString(1);
String titl=rs.getString(2);
String auth=rs.getString(3);
System.out.printf("% - 4s",num);
System.out.printf("% - 6s",titl);
System.out.printf("% - 6s",auth);
}
con.close();
}
catch(SQLException e)
{
System.out.println("sql出错:");
System.out.println(e);
}
}
}
没语法错误
运行:
run:
sql出错:
java.sql.SQLException: [Microsoft][ODBC ??????????] δ???????Դ??Ʋ???δָ??Ĭ???????
成功生成(总时间:0 秒)
:没财富了,给不了悬赏! 展开
import java.sql.*;
public class Main
{
public static void main(String[] args)
{
Connection con;
Statement sql;
ResultSet rs;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e)
{
System.out.println("建立桥接出错:");
System.out.println(e);
}
try
{
String url="jdbc:odbc:driver={Microsoft Access Driver(*.mdb)};DBQ=D:\\Tee_db\\db1.mdb";
con=DriverManager.getConnection(url,"","");
sql=con.createStatement();
rs=sql.executeQuery("select * from music");
while(rs.next())
{
String num=rs.getString(1);
String titl=rs.getString(2);
String auth=rs.getString(3);
System.out.printf("% - 4s",num);
System.out.printf("% - 6s",titl);
System.out.printf("% - 6s",auth);
}
con.close();
}
catch(SQLException e)
{
System.out.println("sql出错:");
System.out.println(e);
}
}
}
没语法错误
运行:
run:
sql出错:
java.sql.SQLException: [Microsoft][ODBC ??????????] δ???????Դ??Ʋ???δָ??Ĭ???????
成功生成(总时间:0 秒)
:没财富了,给不了悬赏! 展开
1个回答
展开全部
import java.sql.*;
public class Main
{
public static void main(String[] args) throws ClassNotFoundException {
Connection con;
Statement sql;
ResultSet rs;
con = null;
try {
String ur1="jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=C:/myfile/qfc.mdb";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"铅培);
con = DriverManager.getConnection(ur1);
sql= con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
rs = sql.executeQuery("纯激梁select * from 设备号'");
while (rs.next()) {
String user = rs.getString("设备号");
System.out.println(user);
}
} catch (Exception e) {
System.out.println("sql出错:");
System.out.println(e);
}
}
}
帮你调好了,做运自己看看,希望采纳
public class Main
{
public static void main(String[] args) throws ClassNotFoundException {
Connection con;
Statement sql;
ResultSet rs;
con = null;
try {
String ur1="jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=C:/myfile/qfc.mdb";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"铅培);
con = DriverManager.getConnection(ur1);
sql= con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
rs = sql.executeQuery("纯激梁select * from 设备号'");
while (rs.next()) {
String user = rs.getString("设备号");
System.out.println(user);
}
} catch (Exception e) {
System.out.println("sql出错:");
System.out.println(e);
}
}
}
帮你调好了,做运自己看看,希望采纳
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询