如何为Sql lite数据库提供连接字符串?(How to give Connection String for Sql lite database?)
首先,我想对于提出这个简单的问题表示歉意。 我正在尝试连接sql-lite数据库表。我正在使用以下代码。
package derb; import java.sql.*; public class db { public static void main(String[] args) throws Exception { Class.forName("org.sqlite.JDBC"); Connection con=DriverManager.getConnection("jdbc:sqlite:/home/anand/MySQLiteDB.TEST","root","ROOT"); Statement st=con.createStatement(); String q="insert into CHECKING values(3)"; st.executeUpdate(q); } }
TEST是我的数据库,我在eclipse中创建了一个名为CHECKING的表。但在上面的代码中给出了错误
Exception in thread "main" java.sql.SQLException: no such table: CHECKING at org.sqlite.DB.throwex(DB.java:288) at org.sqlite.NativeDB.prepare(Native Method) at org.sqlite.DB.prepare(DB.java:114) at org.sqlite.Stmt.executeUpdate(Stmt.java:102) at derb.db.main(db.java:9)
我手动检查了eclipse表是否可用。但我不知道如何建立与该表的连接。所以任何人都可以帮我解决这个问题。
谢谢
First of all i would like to tell my apologies for asking this simple question. i am trying to connect sql-lite database table.I am using following code.
package derb; import java.sql.*; public class db { public static void main(String[] args) throws Exception { Class.forName("org.sqlite.JDBC"); Connection con=DriverManager.getConnection("jdbc:sqlite:/home/anand/MySQLiteDB.TEST","root","ROOT"); Statement st=con.createStatement(); String q="insert into CHECKING values(3)"; st.executeUpdate(q); } }
TEST is my database and i created one table called CHECKING in eclipse.but in above code gives me the error
Exception in thread "main" java.sql.SQLException: no such table: CHECKING at org.sqlite.DB.throwex(DB.java:288) at org.sqlite.NativeDB.prepare(Native Method) at org.sqlite.DB.prepare(DB.java:114) at org.sqlite.Stmt.executeUpdate(Stmt.java:102) at derb.db.main(db.java:9)
I manually checked in the eclipse the table was available.but i don't know how to make the connection to that table.So any one can help me to fix this
Thank you
原文:https://stackoverflow.com/questions/34630193
最满意答案
首先,我们需要确保帖子有一个自定义的
post_meta
字段,您将在其上进行缩短。function whpp_track_post_views($post_id) { if (!is_single()) return; if (empty($post_id)) { global $post; $post_id = $post->ID; } whpp_set_post_views($post_id); } add_action('wp_head', 'whpp_track_post_views'); function whpp_set_post_views($post_id) { $count_key = 'whpp_track_post_views'; $count = get_post_meta($post_id, $count_key, TRUE); if ($count == '') { $count = 0; delete_post_meta($post_id, $count_key); add_post_meta($post_id, $count_key, '0'); } else { $count++; update_post_meta($post_id, $count_key, $count); } } //To keep the count accurate, lets get rid of prefetching remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0); //Short code function function wh_must_post_read() { $html = ''; $args = [ 'meta_key' => 'whpp_track_post_views', //<-- Check This 'orderby' => 'meta_value_num', 'order' => 'DESC', 'posts_per_page' => 5 ]; $my_query_2 = new WP_Query($args); if ($my_query_2->have_posts()) : while ($my_query_2->have_posts()) : $my_query_2->the_post(); $html .= "<p class=\"title\">" . get_the_title() . " </p>"; $html .= "<p>" . get_the_excerpt() . "</p>"; $html .= "<a href=\"" . get_permalink() . "\" class=\"readmore\">Read more</a>"; endwhile; wp_reset_postdata(); endif; return $html; } add_shortcode('wh_must_post', 'wh_must_post_read');
用法
在PHP中echo do_shortcode('[wh_must_post]');
在WP编辑器中
[wh_must_post]
请注意: 要查看此代码的实际操作,请访问几个帖子单页,以便
whpp_set_post_views()
mehord将whpp_track_post_views
meta_key添加到该帖子。以上所有代码都在您的活动子主题(或主题)的function.php文件中。 或者也可以在任何插件的php文件中。
代码经过测试和运行。相关文章: 在没有插件的WordPress中按视图显示热门帖子
相关问题: 如何在wordpress中按日期而不是按日期更改帖子的顺序希望这可以帮助!
First we need to make sure post has a custom
post_meta
fields on which you 'll be doing your shorting.function whpp_track_post_views($post_id) { if (!is_single()) return; if (empty($post_id)) { global $post; $post_id = $post->ID; } whpp_set_post_views($post_id); } add_action('wp_head', 'whpp_track_post_views'); function whpp_set_post_views($post_id) { $count_key = 'whpp_track_post_views'; $count = get_post_meta($post_id, $count_key, TRUE); if ($count == '') { $count = 0; delete_post_meta($post_id, $count_key); add_post_meta($post_id, $count_key, '0'); } else { $count++; update_post_meta($post_id, $count_key, $count); } } //To keep the count accurate, lets get rid of prefetching remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0); //Short code function function wh_must_post_read() { $html = ''; $args = [ 'meta_key' => 'whpp_track_post_views', //<-- Check This 'orderby' => 'meta_value_num', 'order' => 'DESC', 'posts_per_page' => 5 ]; $my_query_2 = new WP_Query($args); if ($my_query_2->have_posts()) : while ($my_query_2->have_posts()) : $my_query_2->the_post(); $html .= "<p class=\"title\">" . get_the_title() . " </p>"; $html .= "<p>" . get_the_excerpt() . "</p>"; $html .= "<a href=\"" . get_permalink() . "\" class=\"readmore\">Read more</a>"; endwhile; wp_reset_postdata(); endif; return $html; } add_shortcode('wh_must_post', 'wh_must_post_read');
USAGE
In PHPecho do_shortcode('[wh_must_post]');
In WP Editor
[wh_must_post]
Please Note: To see this code in action visit few post single page so that
whpp_set_post_views()
mehord will addwhpp_track_post_views
meta_key to that post.All the above code goes in function.php file of your active child theme (or theme). Or also in any plugin php files.
Code is tested and works.Related Article: Display Popular Posts by Views in WordPress without a Plugin
Related Question : How to change the order of posts by number of views not by date in wordpressHope this helps!
相关问答
更多-
Unyson框架中的WP_Query Loop中不存在$ post变量。($post variable isn't exist in WP_Query Loop in Unyson framework.)[2022-03-12]
在循环中使用get_the_ID ,如: $post_id = get_the_ID(); $args = array( 'post_type' => 'elements', ); $query = new WP_Query( $args ); if($query->have_posts()): while( $query->have_posts()): $query->the_post(); ?> $post_id = get_the_ID(); ... -
越来越多的WordPress越来越多,我知道我的错。 缺点是元键值没有存储在数据库中,这就是为什么我的热门帖子没有显示。 我只需要几个步骤就可以做到这一点: 我们需要做的第一件事是创建一个函数,该函数将检测后视图计数并将其作为每个帖子的自定义字段存储: function wpb_set_post_views($postID) { $count_key = 'wpb_post_views_count'; $count = get_post_meta($postID, $count_key, true); i ...
-
具有2个帖子的Wordpress Wp_query对象仅打印一个(Wordpress Wp_query object with 2 posts prints only one)[2022-01-13]
尝试这样做 foreach ($id as $key => $value) { if ($value == 4){ //this is the categorie with two posts $posts_query = new WP_Query( array('posts_per_page' => 2, 'category__in' => array($value))); } else { $posts_query ... -
它很可能是浏览器缓存,因为浏览器倾向于存储样式表,并且图像页面内容通常在页面被加载时被重新解释,因为它已经改变。 它更有可能是在服务器上兑现或者另一个第三方服务,如Cloud flare,它将页面外观存储一段时间,以保存一遍又一遍地重新生成相同的动态页面控件。 WP_Engine托管有它自己的缓存,可以通过安装仪表板清除,Cloud flare允许缓存清除每个URL和插件......以及这些都是不同的,检查是否有任何插件控制缓存并关闭它们而您正在进行更改或清除缓存。 it is ulikely to be ...
-
弄清楚了 - 我'排除'第一个循环数组中的类别ID以将其删除,因此在第二个循环中,我'包含'相同的类别ID。 太简单了...我虽然将ID和其他ID一起包含在内,但认为它是多余的。 无论如何,谢谢你的帮助! '367' ); $categories = get_categories( $args ); $parent_categories = ''; foreach ( $categories as $category ) { ? ...
-
尝试这个 : $the_post_query = new WP_Query ( 'name' => $_SERVER['REQUEST_URI'] ); $is_valid_post = ! empty ( $the_post_query -> queried_object -> post_title ); 我没有测试过,但它应该可以工作。 来自代码的参考: https://codex.wordpress.org/Class_Reference/WP_Query#Search_Parameter Afte ...
-
有几个相同的插件: https://wordpress.org/plugins/ajax-load-more/ https://wordpress.org/plugins/easy-load-more/ 你也可以用自定义的方式来做到这一点。 你可以从这里参考。 在Wordpress中加载更多文章Ajax Button https://madebydenis.com/ajax-load-posts-on-wordpress/ There is couple of plugin for same : https ...
-
在你的班级中声明短代码。 我刚刚做了这个,并使用本教程来帮助: https : //code.tutsplus.com/articles/create-wordpress-plugins-with-oop-techniques--net-20153 编辑:我会添加一个单独的函数称为get_widget_contents($猫); function get_widget_contents($cat) { $args = array( 'post_type' => 'post', ...
-
首先,我们需要确保帖子有一个自定义的post_meta字段,您将在其上进行缩短。 function whpp_track_post_views($post_id) { if (!is_single()) return; if (empty($post_id)) { global $post; $post_id = $post->ID; } whpp_set_post_views($post_id); } add_action( ...
-
wp中相关帖子的短代码(shortcode for related post in wp)[2023-03-04]
如果要显示给定的标签帖子,则无需使用wp_get_post_tags(),因为它返回多个标签。 试试这段代码, function fphp_get_related_posts( $atts ) { $atts = shortcode_atts( [ 'tag' => '', ], $atts ); $args = [ 'posts_per_page' => 1, 'tag' => $atts['tag'], 'orderby' => 'rand' ]; $query = ...