unable to open database file 50
求大神们指教GetWeather.java:28行代码是publicstaticSQLiteDatabasewdb=SQLiteDatabase.openOrCreate...
求大神们指教
GetWeather.java :28行代码是
public static SQLiteDatabase wdb =SQLiteDatabase.openOrCreateDatabase(f, null); 展开
GetWeather.java :28行代码是
public static SQLiteDatabase wdb =SQLiteDatabase.openOrCreateDatabase(f, null); 展开
1个回答
展开全部
/**
*
*/
package sqlIte;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
/**
* @author Administrator
*
*/
public class SqlIteTest {
/**
* @author : haoming
* @date : 2012-11-28上午10:02:36
* @111 sqlIte.SqlIteTest.java.main
* @returnType : void
* @desc :
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("test start ... ");
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs=null;
try {
Class.forName("org.sqlite.JDBC");
// conn = DriverManager.getConnection("jdbc:sqlite:unity_db.db");
conn = DriverManager.getConnection("jdbc:sqlite:src/sqlIte/unity_db.db");
// conn = DriverManager.getConnection("jdbc:sqlite:/F:/MyEclipse8.5_workbanch_svn/111/src/sqlIte/unity_db.db");
conn.setAutoCommit(false);
ps = conn.prepareStatement("pragma table_info(t_mptype) ");
rs = ps.executeQuery();
while(rs.next()){
System.out.println(rs.getString("cid")+"~"+rs.getString("name")+"~"+rs.getString("type")+"~"+rs.getString("notnull")+"~"+rs.getString("dflt_value")+"~"+rs.getString("pk"));
}
ps = conn.prepareStatement("select * from t_mptype ");
rs = ps.executeQuery();
while (rs.next()) {
int id = rs.getInt(1);
String name = rs.getString(3);
System.out.println("id=" + id + ", name=" + name);
}
rs.close();
ps.close();
conn.commit();
} catch (Exception e) {
e.printStackTrace();
try {
if (conn != null && !conn.isClosed()) {
conn.rollback();
}
} catch (SQLException sql) {
}
}finally{
try {
conn.close();
ps.close();
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
System.out.println("test end ... ");
}
}
// 需要导入sqlitejdbc-v033-nested.jar
*
*/
package sqlIte;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
/**
* @author Administrator
*
*/
public class SqlIteTest {
/**
* @author : haoming
* @date : 2012-11-28上午10:02:36
* @111 sqlIte.SqlIteTest.java.main
* @returnType : void
* @desc :
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("test start ... ");
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs=null;
try {
Class.forName("org.sqlite.JDBC");
// conn = DriverManager.getConnection("jdbc:sqlite:unity_db.db");
conn = DriverManager.getConnection("jdbc:sqlite:src/sqlIte/unity_db.db");
// conn = DriverManager.getConnection("jdbc:sqlite:/F:/MyEclipse8.5_workbanch_svn/111/src/sqlIte/unity_db.db");
conn.setAutoCommit(false);
ps = conn.prepareStatement("pragma table_info(t_mptype) ");
rs = ps.executeQuery();
while(rs.next()){
System.out.println(rs.getString("cid")+"~"+rs.getString("name")+"~"+rs.getString("type")+"~"+rs.getString("notnull")+"~"+rs.getString("dflt_value")+"~"+rs.getString("pk"));
}
ps = conn.prepareStatement("select * from t_mptype ");
rs = ps.executeQuery();
while (rs.next()) {
int id = rs.getInt(1);
String name = rs.getString(3);
System.out.println("id=" + id + ", name=" + name);
}
rs.close();
ps.close();
conn.commit();
} catch (Exception e) {
e.printStackTrace();
try {
if (conn != null && !conn.isClosed()) {
conn.rollback();
}
} catch (SQLException sql) {
}
}finally{
try {
conn.close();
ps.close();
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
System.out.println("test end ... ");
}
}
// 需要导入sqlitejdbc-v033-nested.jar
追问
我这是android数据库
追答
你说的是在安卓使用的数据库吧。一般情况下那是sqlite数据库。就是这样写没问题。【不同之处在于数据库文件的路径不同】
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询