我最近遇到了Java PreparedStatements的这个问题.我有以下代码:
String selectSql1
= "SELECT `value` FROM `sampling_numbers` WHERE `value` < (?)" ;
ResultSet rs1 = con.select1(selectSql1,randNum);
Run Code Online (Sandbox Code Playgroud)
select1
方法在哪里
public ResultSet select1(String sql, int randNum) {
try {
this.stmt = con.prepareStatement(sql);
stmt.setInt(1, randNum);
return this.stmt.executeQuery(sql);
} catch (SQLException e) {
e.printStackTrace();
return null;
}
}
Run Code Online (Sandbox Code Playgroud)
但是,它不断抛出此错误:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?)' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) …
Run Code Online (Sandbox Code Playgroud) 鉴于ChoiceField
Django中的一个
fruits = ChoiceField(label="Fruits", choices=(('A', 'Apple'),
('B', 'Banana'), ('C', 'Cherry')
)
Run Code Online (Sandbox Code Playgroud)
如何在1.9中的Django模板中显示表单选项?例如,我尝试了以下但无法显示表单数据:
<table class="table table-bordered table-condensed">
<tr>
<th>
<label for="{{form.fruits.id_label}}">
{{form.fruits.label}}
</label>
</th>
<td>{% for value, displayable in form.fruits.choices %}
<option value="{{value}}">{{displayable}}</option>
{% endfor %}
</td>
</tr>
</table>
Run Code Online (Sandbox Code Playgroud) 假设我有一个Shelf
班级,每个班级Shelf
都有多个Book
.
public class Shelf{
private String shelfCode;
private ArrayList<Book> books; //add getters, setters etc.
}
public class Book{
private String title;
}
Run Code Online (Sandbox Code Playgroud)
现在,让我们从一些方法,我有发言权List
的Shelf
S,每个都包含了一些书.如何使用stream
收集此列表中的所有书籍?
List<Shelf> shelves = new ArrayList<Shelf>();
Shelf s1 = new Shelf();
s1.add(new Book("book1"));
s1.add(new Book("book2"));
Shelf s2 = new Shelf();
s1.add(new Book("book3"));
s1.add(new Book("book4"));
shelves.add(s1);
shelves.add(s2);
List<Book> booksInLibrary = //??
Run Code Online (Sandbox Code Playgroud)
我在想类似的东西
List<Book> booksInLibrary =
shelves.stream()
.map(s -> s.getBooks())
.forEach(booksInLibrary.addall(books));
Run Code Online (Sandbox Code Playgroud)
但它似乎不起作用,抛出编译错误.
尝试查看日志时,Airflow会抛出一个带有以下消息的oops页面:
File "/Users/user/.pyenv/versions/3.5.2/lib/python3.5/locale.py", line 486, in _parse_localename
raise ValueError('unknown locale: %s' % localename)
Run Code Online (Sandbox Code Playgroud)
ValueError:未知语言环境:UTF-8
因此,我按照建议添加了以下几行:
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
Run Code Online (Sandbox Code Playgroud)
并经过验证:
(airflow-local) user-mbp:Desktop user$ echo $LC_ALL
en_US.UTF-8
(airflow-local) user-mbp:Desktop user$ echo $LANG
en_US.UTF-8
Run Code Online (Sandbox Code Playgroud)
但是该错误仍在显示。需要做的缺失的事情是什么?
我刚开始使用Facebook Graph API.
如何通过1个FB.api调用来调用多个属性?现在,我有
FB.api('/me', function(me){
if (me) {
var myEmail = me.email;
var myID = me.id;
var myFirst_name = me.first_name;
//Other attributes
}
});
Run Code Online (Sandbox Code Playgroud)
和
FB.api('/me/friends',{ fields: 'name,id' }, function(response){
var friends = response.data;
}
});
Run Code Online (Sandbox Code Playgroud)
如何将两个api调用合并为一个,比如说只有1个FB.api()
调用?
所有回复都会真的很有帮助.
javascript javascript-events facebook-graph-api facebook-javascript-sdk
我一直试图在Django管理员中解决这个问题但仍无法找到文档.
在我的models.py中,我有以下代码:
from django.db import models
class Post(models.Model):
title = models.CharField(max_length=200)
author = models.ForeignKey('Author', blank=False)
class Author(models.Model):
first_name = models.CharField('First Name',max_length=50)
last_name = models.CharField('Last Name', max_length=50, blank=True)
description = models.CharField(max_length=500, blank=True)
def __str__(self):
return (self.first_name + ' ' + self.last_name)
Run Code Online (Sandbox Code Playgroud)
在 django.contrib导入管理员的admin.py中
# Register your models here.
from .models import Author, Post
class PostAdmin(admin.ModelAdmin):
list_display = ['title', 'author', 'get_author_description']
admin.site.register(Post, PostAdmin)
Run Code Online (Sandbox Code Playgroud)
但是,每次运行服务器时,我都会收到错误消息
<class 'blog.admin.PostAdmin'>: (admin.E108) The value of
'list_display[2]' refers to 'get_author_description', which is not a
callable, …
Run Code Online (Sandbox Code Playgroud) 我在 Bootstrap 的导航栏上有一堆链接
<ul class="nav navbar-nav">
<li ><a href="{% url 'home' %}">Home</a></li>
<li ><a href="{% url 'about' %}">About</a></li>
<li ><a href="{% url 'contact' %}">Contact</a></li>
</ul>
Run Code Online (Sandbox Code Playgroud)
假设我在“主页”部分,我想<li class="active">
在 Django 上添加一个文本。
我的第一直觉是将上下文变量用于views.py并执行类似的操作
context = { 'section' : 'home' }
Run Code Online (Sandbox Code Playgroud)
然后做字符串的匹配
<ul class="nav navbar-nav">
<li {% if section == 'home' %}class="active"{% endif %}><a href="{% url 'home' %}">Home</a></li>
<li {% if section == 'about' %}class="active"{% endif %}><a href="{% url 'about' %}">About</a></li>
<li {% if section == 'contact' %}class="active"{% endif %}><a …
Run Code Online (Sandbox Code Playgroud) 在我的模特中,我有DateTimeField
发言权
class ReturnEvent(models.Model):
book_title = models.CharField()
return_time = models.DateTimeField()
Run Code Online (Sandbox Code Playgroud)
当我检索return_time
要打印时,例如:
return_event = ReturnEvent.objects.get(id=1)
print(return_event.return_time.strftime("%H:%M"))
Run Code Online (Sandbox Code Playgroud)
我看到日期时间没有意识到的时间如下:
2016-06-18 08:18:00+00:00
但是,我喜欢使用strftime查看当地时间.
2016-06-18 10:18:00+02:00
对此有快速解决方案吗?
我对 PEP 8 中的样式有疑问(或将每行中的字符数减少到更小)。
考虑到我有book
一堆不同的属性,我想将它们连接成一些字符串。
books = [book_1, book_2, book_3]
for b in books:
print("Thank you for using our Library! You have decided to borrow %s on %s. Please remember to return the book in %d calendar days on %s" %
(book.title, book.start_date, book.lend_duration, book.return_date"))
Run Code Online (Sandbox Code Playgroud)
如何缩短此行以确保其可读性?
任何想法都会有所帮助。PEP 8 只是一个想法。
给出一个df
in[0]df1
out[0]
DATE REVENUE COST POSITION
FACTOR
0 2017/01/01 1000 900 10
1 2017/01/01 900 700 9
2 2017/01/01 1100 800 7
Run Code Online (Sandbox Code Playgroud)
我有一个额外的行FACTOR
.尝试reset_index()
和其他方式后,我无法删除FACTOR
多(行)索引.有办法吗?
我知道删除列并重置索引很常见,但不是这样.
django ×4
python ×3
java ×2
airflow ×1
django-forms ×1
java-stream ×1
javascript ×1
mysql ×1
pandas ×1
pep8 ×1
python-3.4 ×1
pytz ×1