我想更好地熟悉JPA,所以我创建了一个非常简单的项目.我有一个User Class和一个Address类.看来我必须坚持两个,即使我正在向我的用户类添加地址?
用户:
import javax.persistence.*;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@Entity
@Table(name = "usr") // @Table is optional, but "user" is a keyword in many SQL variants
@NamedQuery(name = "User.findByName", query = "select u from User u where u.name = :name")
public class User {
@Id // @Id indicates that this it a unique primary key
@GeneratedValue // @GeneratedValue indicates that value is automatically generated by the server
private Long id;
@Column(length = 32, unique = true)
// the …Run Code Online (Sandbox Code Playgroud) 有没有可能我的后续BufferedReader能够将输入直接放入byte []?
public static Runnable reader() throws IOException {
Log.e("Communication", "reader");
din = new DataInputStream(sock.getInputStream());
brdr = new BufferedReader(new InputStreamReader(din), 300);
boolean done = false;
while (!done) {
try {
char[] buffer = new char[200];
int length = brdr.read(buffer, 0, 200);
String message = new String(buffer, 0, length);
btrar = message.getBytes("ISO-8859-1");
int i=0;
for (int counter = 0; counter < message.length(); counter++) {
i++;
System.out.println(btrar[counter] + " = " + " btrar " + i);
}
...
Run Code Online (Sandbox Code Playgroud)
这是读者的一部分,请看看.
我想直接输入到btrar,
我有一个漂亮而紧凑的代码,它不能像我预期的那样工作.
public class Test {
public static void main(String[] args) {
Runnable r = new Runnable() {
@Override
public void run() {
try {
for (;;) {
}
} finally {
System.out.println("FINALLY");
}
}
};
ExecutorService executor = Executors.newSingleThreadExecutor();
Future<?> future = executor.submit(r);
try {
future.get(3, TimeUnit.SECONDS);
} catch (TimeoutException e) {
boolean c = future.cancel(true);
System.out.println("Timeout " + c);
} catch (InterruptedException | ExecutionException e) {
System.out.println("interrupted");
}
System.out.println("END");
}
}
Run Code Online (Sandbox Code Playgroud)
输出是:
超时是真的
结束
问题:为什么不终止future.cancel(true)方法调用Runnable?程序将"END"写入输出后,"r"Runnable仍在运行.
我有Windows窗体应用程序,其中包含多个窗体和控件.我希望如果用户在任何形式的应用程序的任何控件中选择了一些文本,并单击工具栏操作上的剪切/复制/粘贴按钮,则相应地执行.
我在点击复制按钮时使用C#.net的sendkeys.send("^ c")但它不起作用...
或任何1可以判断是否有任何方式来获取所选文本(尽管知道,我的应用程序的形式/控制).
提前致谢...
我只是想知道是否可以将窗体停靠在用户屏幕的顶部?我一直试图通过手动将表单的位置设置为我想要的坐标来做到这一点.但是,使用此方法,用户只需拖动即可更改表单的位置.我想使表单停靠在屏幕的上半部分,因为这个窗口表单将作为我正在制作的项目的菜单服务器.
非常感谢.:)
我无法将控制台输出重定向到Windows窗体文本框.问题与线程有关.我正在以下列方式运行控制台应用程序,
private void RunConsoleApp()
{
Process proc = new Process();
proc.StartInfo.FileName = "app.exe";
proc.StartInfo.Arguments = "-a -b -c";
proc.StartInfo.UseShellExecute = false;
// set up output redirection
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.RedirectStandardError = true;
proc.EnableRaisingEvents = true;
proc.StartInfo.CreateNoWindow = true;
// Set the data received handlers
proc.ErrorDataReceived += proc_DataReceived;
proc.OutputDataReceived += proc_DataReceived;
proc.Start();
proc.BeginErrorReadLine();
proc.BeginOutputReadLine();
proc.WaitForExit();
if (proc.ExitCode == 0)
{
out_txtbx.AppendText("Success." + Environment.NewLine);
}
else
{
out_txtbx.AppendText("Failed." + Environment.NewLine);
}
}
Run Code Online (Sandbox Code Playgroud)
然后使用此输出处理程序捕获和处理数据,
// Handle the date received by the console process …Run Code Online (Sandbox Code Playgroud) int array[] = {-1, 4, -2, 5, -5, 2, -20, 6};
Run Code Online (Sandbox Code Playgroud)
如果我有那个数组,我的Kadane算法实现找到最大的子数组工作:
int max_so_far = INT_MIN;
int max_ending_here = 0;
for (int i = 0; i < size; i++) {
max_ending_here = max(max_ending_here + array[i], 0);
max_so_far = max(max_ending_here, max_so_far);
}
printf("%d\n", max_so_far);
Run Code Online (Sandbox Code Playgroud)
但是,如果我有一个所有负数的数组:
int array[]= {-10, -10, -10};
Run Code Online (Sandbox Code Playgroud)
它不起作用,它应该返回-10,但我得到0.
我怎样才能让它对负数起作用?
谢谢!
我想知道下面的代码的确切替换,没有弃用的代码.此外,我想在新的Facebook SDK 3.0中尝试它.
Facebook aFacebook = new Facebook("app_id");
if( !aFacebook.isSessionValid() ) {
aFacebook.authorize(this, new String[] { "email" },
new LoginDialogListener());
}
Run Code Online (Sandbox Code Playgroud)
我尝试了很多东西.但是,无法完成它.
TIA
.NET Windows窗体应用程序是否使用等效的本机Win32控件来实现Textbox和Button等基本控件?WPF是非本机的,但Windows Forms的外观和感觉非常原生.Button控件上的动画看起来与Win32按钮完全相同.
如何获取查询中错误的位置?
我需要在导致错误的查询字符串中获取位置,就像sqlplus这样:
SQL> insert into tbl (data) values('12345')
2 /
insert into tbl (data) values('12345')
*
ERROR at line 1:
ORA-12899: value too large for column "schmnm"."tbl"."data" (actual: 5,
maximum: 3)
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?