我正在尝试在mac上运行一个简单的sqlite示例.我很确定该代码在Windows上运行良好.但不是在Mac上.如果有人能帮助我,我真的很感激.
代码在Eclipse中运行.我在项目中添加了sqlite-jdbc4-3.8.2-SNAPSHOT.jar作为内部和外部jar.
public class Test1 {
private static Connection c;
private static String filepath = "/Users/zerocraft/Documents/workspace/sql_test/";
private static String sql;
private static Statement query;
public static void main(String[] args) {
System.out.println("START");
try{
Class.forName("org.sqlite.JDBC");
System.out.println("START2");
c = DriverManager.getConnection("jdbc:sqlite:"+filepath+"projone.db");
System.out.println("START3");
}
catch(Exception e){
e.printStackTrace();
}
sql = "INSERT INTO table(date,time,client_id,run_id,latitude," +
"longitude,bearing,speed,altitude,sensor_id,sensor_type," +
"sensor_value,attribute)"
+ "VALUES ('A','B','C','D',0,1,2,3,4,'E','F','G','H')";
try{
query = c.createStatement();
query.executeUpdate(sql);
query.close();
}
catch(SQLException el){el.printStackTrace();}
}
}
Run Code Online (Sandbox Code Playgroud)
START
START2
Exception in thread "main" java.lang.NoClassDefFoundError: org/sqlite/NativeDB
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at …Run Code Online (Sandbox Code Playgroud) 我正在Mac osx上运行sqlite c ++演示。我从下面显示的网页复制了代码。
参考:http : //www.tutorialspoint.com/sqlite/sqlite_c_cpp.htm
源代码是
//
#include <stdio.h>
#include <stdlib.h>
#include <sqlite3.h>
#include <fstream>
#include <string>
using namespace std;
static int callback(void *NotUsed, int argc, char **argv, char **azColName){
int i;
for(i=0; i<argc; i++){
printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
}
printf("\n");
return 0;
}
int main(int argc, char* argv[])
{
sqlite3 *db;
char *zErrMsg = 0;
int rc;
char *sql;
string str;
/* Open database */
rc = sqlite3_open("test.db", &db);
if( rc …Run Code Online (Sandbox Code Playgroud) 我最近在做Leetcode https://oj.leetcode.com/。假设p是一个指针,有趣的是我使用的时候运行时间是不一样的
if(p==NULL)
Run Code Online (Sandbox Code Playgroud)
和
if(!p)
Run Code Online (Sandbox Code Playgroud)
第一个比第二个花费更少的时间。它们之间有什么区别吗?谢谢!
更新:
