如何将Java连接到Mysql?

我的Java程序出现了这些错误。 我已经将mysql-connector-java-5.1.14-bin.jar放在了我的类路径中。 怎么解决这个? HSystemRDB.java:144: package com.mysql.jdbc does not exist Driver driver = new com.mysql.jdbc.Driver(); ^ HTestClassRDB.java:99: package com.mysql.jdbc does not exist DriverManager.registerDriver(new com.mysql.jdbc.Driver()); 代码: String url = “jdbc:mysql://wire:3306/h?user=”+pSystemRDB.USERNAME+”&password=”+pSystemRDB.PASSWORD; Connection con; Statement stmt; String query1 = “Delete from dbase”; String query2 = “Delete from id”; try { DriverManager.registerDriver(new com.mysql.jdbc.Driver()); } catch (Exception e) { System.out.println(“Class Not […]

JPanel不响应KeyListener事件

我有一个JFrame的子类,它使用从JPanel扩展的类 public class HelloWorld extends JPanel implements KeyListener 我在框架中添加了一个HelloWorld对象 – app.add(helloWorld); 。 现在,当我按下任何键盘键时,不会调用KeyListener方法,并且似乎helloWorld没有窗口焦点。 我也尝试过调用helloWorld.requestFocusInWindow(); 但仍然没有回应。 如何使其响应按键?

得到java.lang.StringIndexOutOfBoundsException错误

而我正在做一个简单的密码程序。 我遇到了这个错误 Exception in thread “main” java.lang.StringIndexOutOfBoundsException: String index out of range: -1 at java.lang.String.charAt(Unknown Source) at Caesar.main(Caesar.java:27) 好吧,我不清楚原因是什么。 我需要一些老手的帮助@@下面是我的代码。 import java.util.Scanner; import java.io.FileReader; import java.io.IOException; import java.io.PrintWriter; public class Caesar { public static void main(String[] args){ String from = “abcdefghijklmnopqrstuvwxyz”; String to = “feathrzyxwvusqponmlkjigdcb”; Scanner console = new Scanner(System.in); System.out.print(“Input file: “); String inputFileName […]

java解析字符串到目前为止

我试图解析2011年3月14日到Java的日期转换器应用程序…我得到2010年12月26日…请帮忙。 import java.util.*; import java.text.*; class date { public static void main(String[] args) { try { String timestampOrig = “11/03/14,15:00:00”; SimpleDateFormat inFormat = new SimpleDateFormat(“YY/MM/dd’,’HH:mm:ss”); Date parseDate = inFormat.parse(timestampOrig); System.out.println(“parsed date: ” + parseDate.toString()); } catch(ParseException pe){ } } } 输出: 解析日期:美国东部时间2010年12月26日15:00:00

java中字符串的字体设置

我可以在java中为字符串设置字体属性。

返回数字的第n位数

public class Return { public static void main(String[] args) { int answer = digit(9635, 1); print(“The answer is ” + answer); } static void print(String karen) { System.out.println (karen); } static int digit(int a, int b) { int digit = a; return digit; } } 创建一个程序,该程序使用一个名为digit的函数,该函数返回整数参数右侧第n位的值。 n的值应该是第二个参数。 例如: digit(9635, 1)返回5 , digit(9635, 3)返回6 。

Admob广告未在屏幕方向上正确resize

我在我的应用中使用Admob广告,但我遇到了问题。 每当我将屏幕转为横向模式时,广告就会显示,但它与纵向模式下的尺寸相同。 在我的清单中将此xml声明添加到我的主要活动之后出现此问题,这是保持应用程序主要部分顺利运行所必需的: android:configChanges=”orientation|keyboardHidden|screenSize” 我在广告中使用智能横幅尺寸: ads:adSize=”SMART_BANNER” 我附上了这个问题的图片: 我必须做些什么才能让广告在横向模式下正确resize而不删除 android:configChanges=”orientation|keyboardHidden|screenSize” 在我的主要活动的清单?

改变JButton的背景

我有一个Swing JButton,我也在为我的项目使用以下代码: UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 现在尝试使用btnNewButton.setBackground(Color.RED);更改一个按钮的背景时btnNewButton.setBackground(Color.RED); 它不会变红,只有边框变红。 如何在仍为其余组件/项目使用UIManager.getSystemLookAndFeelClassName()同时将此背景变为红色?

发布值并将图像上传到android中的php服务器

我试图将图像从Android手机上传到带有附加值的php服务器,该方法是发布我的php文件看起来像这样 if($_POST[‘val1’]){ if($_POST[‘val2’]){ if($_FILE[‘image’]){ …… } } }else{ echo “Value not found”; } 我正在做的 URL url=new URL(“http://www/……../myfile.php”); HttpURLConnection con=(HttpURLConnection) url.openConnection(); con.setDoInput(true); con.setDoOutput(true); con.setUseCaches(false); con.setRequestMethod(“POST”);//Enable http POST con.setRequestProperty(“Connection”, “Keep-Alive”); con.setRequestProperty(“Content-Type”, “multipart/form-data;boundary=”+”****”); connection.setRequestProperty(“uploaded_file”, imagefilePath); DataOutputStream ostream = new DataOutputStream( con.getOutputStream()); String res=(“Content-Disposition: form-data; name=\”val1\””+val1+”****”+ “Content-Disposition: form-data; name=\”val2\””+val2+”****” “Content-Disposition: form-data; name=\”image\”;filename=\”” + imagefilePath +”\””+”****”); outputStream.writeBytes(res); 我的实际问题是,如果条件为false,则首先不发布值,否则执行部分,即它找不到值,请帮助我

Java系统剪贴板可以复制文件吗?

我使用Java系统剪贴板来传输文本和图像,但我想知道它是否可以复制和粘贴文件? 如果是这样我在哪里可以找到一些示例代码? 我发现了一个类似的问题: 如何使用Java复制文件并将其粘贴到剪贴板? 但我无处可找到“剪贴板”这个词,我不知道如何使用它。 我用来复制图像的方法如下所示: public static void setClipboard(Image image) // This method writes a image to the system clipboard : from exampledepot.com { ImageSelection imgSel=new ImageSelection(image); Toolkit.getDefaultToolkit().getSystemClipboard().setContents(imgSel,null); } public Image getImageFromClipboard() // Get an image off the system clipboard { Transferable transferable=Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null); if (transferable!=null&&transferable.isDataFlavorSupported(DataFlavor.imageFlavor)) { try { return (Image)transferable.getTransferData(DataFlavor.imageFlavor); } catch (UnsupportedFlavorException e) […]