将netbeans(JAVA)连接到MYSQL(Connecting netbeans (JAVA) to MYSQL)
问题是当我运行这段代码时,我总是得到答案COL12,而不是像我在
MYSQL
工作台中得到的所有数据列。 我需要得到相同的价值观。 此外,当我使用此查询“DELETE FROM test WHERE col1 = 2;”时 在netbeans我得到错误异常。这是我在Netbeans中编写的代码。
包装箱;import java.sql.*; import java.sql.Statement; import java.sql.DriverManager; public class Temp_Class { public static void main(String[] args){ try { String query="SELECT * FROM test"; Class.forName("com.mysql.jdbc.Driver"); Connection con= DriverManager.getConnection("jdbc:mysql://localhost/JavaProject", "root", "19881990"); Statement st=con.createStatement(); ResultSet rs=st.executeQuery(query); rs.next(); String sname= rs.getString(2); System.out.println(sname); con.close(); } catch (Exception e) { System.out.println("Error"); } } }
我在
MYSQL
Workbench中进行了表测试,其中columns =“col1,col2,col3”,其中values =“1,COL11,COL12”和“2,COL21,COL22”;这是我用来删除DB中的值的代码。 。 。 但得到错误异常。
public static void main(String[] args){ try { String deletesql="DELETE FROM test WHERE col1 = 2"; Class.forName("com.mysql.jdbc.Driver"); Connection con= DriverManager.getConnection("jdbc:mysql://localhost/JavaProject", "root", "19881990"); Statement st=con.createStatement(); ResultSet rs=st.executeQuery(select); Statement ds=con.createStatement(); ResultSet dsrow=ds.executeQuery(deletesql); dsrow.next(); String ds1= dsrow.getString(1); String ds2= dsrow.getString(2); String ds3= dsrow.getString(3); System.out.println(ds1+" "+ ds2+" "+ds3); con.close(); } catch (Exception e) { System.out.println("Error"); } }
The problem is when I run this code, I always get answer COL12 instead of getting all the columns with data like I am getting in
MYSQL
workbench. I need to get same values. Moreover when I use this query "DELETE FROM test WHERE col1 = 2;" in netbeans I get Error Exception.Here is my Code I wrote in Netbeans.
package sams;import java.sql.*; import java.sql.Statement; import java.sql.DriverManager; public class Temp_Class { public static void main(String[] args){ try { String query="SELECT * FROM test"; Class.forName("com.mysql.jdbc.Driver"); Connection con= DriverManager.getConnection("jdbc:mysql://localhost/JavaProject", "root", "19881990"); Statement st=con.createStatement(); ResultSet rs=st.executeQuery(query); rs.next(); String sname= rs.getString(2); System.out.println(sname); con.close(); } catch (Exception e) { System.out.println("Error"); } } }
I have made table test in
MYSQL
Workbench, with columns="col1, col2, col3" with values="1, COL11, COL12" and "2, COL21, COL22";This is the code I use to delete a value in DB. . . but getting Error Exception.
public static void main(String[] args){ try { String deletesql="DELETE FROM test WHERE col1 = 2"; Class.forName("com.mysql.jdbc.Driver"); Connection con= DriverManager.getConnection("jdbc:mysql://localhost/JavaProject", "root", "19881990"); Statement st=con.createStatement(); ResultSet rs=st.executeQuery(select); Statement ds=con.createStatement(); ResultSet dsrow=ds.executeQuery(deletesql); dsrow.next(); String ds1= dsrow.getString(1); String ds2= dsrow.getString(2); String ds3= dsrow.getString(3); System.out.println(ds1+" "+ ds2+" "+ds3); con.close(); } catch (Exception e) { System.out.println("Error"); } }
原文:
最满意答案
我猜这两个if语句中的一个正在评估为false:
if image: if image.primary_image: url = images.get_serving_url(str(image.primary_image.key()))
如果您实际调用了get_serving_url,则可能会获得有效的服务URL或异常。 相反,url仍然有它的起始值,一个空字符串。
I would guess that one of these two if statements is evaluating to false:
if image: if image.primary_image: url = images.get_serving_url(str(image.primary_image.key()))
If you were actually calling get_serving_url, you would either get a valid serving URL or an exception. Instead, url still has its starting value, a blank string.
相关问答
更多-
很简单,在TCPDF中引用图像时,不要使用/images/myimage.png等绝对链接 TCPDF不使用网站家庭结构,它使用基本操作系统目录结构。 因此,如果folde图像与tcpdf php文件位于同一文件夹中,请使用相关链接,例如:images / myimage.png。 或者../../ images/myimage.png如果它低于tcpdf文件夹。 我有同样的问题引用我的TTF字体文件。 应该很容易解决。 Simple, when referencing your image in TCPD ...
-
来自网站的图片(Image from website)[2024-03-21]
假设图像URL在每个月都不一致,我会使用TFHpple,当应用加载时,解析DOM搜索@"//img"并从结果中提取src URL属性。 这个教程非常适合TFHpple。 Assuming the image URLs are not consistent from month to month I would use TFHpple and when the app loads, parse the DOM searching for @"//img" and pull the src URL attrib ... -
全屏图片(Fullscreen image)[2024-04-04]
我已经用这种方式解决了 System.Windows.Size dimensions = ResolutionHelper.ScreenResolution; BitmapImage wb = new BitmapImage(); wb.SetSource(myStreamPhoto); ImgChosenPhoto.Source = wb; ImgChosenPhoto.Height = (int)dimensions.Height; ImgChosenPhoto.Width = (int)dime ... -
android图片问题(android Image problem)[2022-10-20]
资源名称必须是正确的Java标识符。 称他们为card52至card52而不仅仅是他们的号码(如果我理解你的话)。 编辑添加:要将整数映射到正确的图像,您的代码应该管理映射本身。 一种(不是非常优雅)的方式是显式创建一个Bitmap[] cardImages = new Bitmap[52]; 数组并将每个资源分配到数组中,如例如 Resources r = context.getResources(); cardImages[0] = loadBitmap(r.getDrawable(R.drawable ... -
我修正了你的代码: var rotation = 0; function draw(){ var ctx = document.getElementById('myCanvas').getContext('2d'); ctx.globalCompositeOperation = 'destination-over'; ctx.save(); ctx.clearRect(0,0,200,200); ctx.translate(100,100); // to get it in the ...
-
为什么没有图片显示?(Why no image shows?)[2022-05-26]
有关通过意图打开图像的信息,请参阅此主题,或者您可以查看此处 See this thread regarding opening image via intent or you can take a look over here -
图片旁边的图片(Image next to a Division)[2022-10-08]
说实话,我觉得你可能会采取一些错误的方法。 我个人会把这个图标作为CSS background-image附加到div。 之后,您可以在div的左侧应用填充等于图像的宽度(加上几个像素的间距)。 然后,您将能够使用background-position来执行以下操作: background-position:0px center; 这将为您提供我认为您所追求的更高程度的控制。 To be honest from your example I have a feeling you may be taking ... -
如何上传图片?(how to upload image?)[2021-11-07]
对于images/您已经检查了Linux上的权限,它将是755或777。 注意:您不需要绝对路径,您甚至可以在下面执行此操作。 $to = "images/".$_FILES['userfile']['name']; for images/ have you checked the Permission on Linux it will be 755 or 777. Note: You don't need absolute path for that you can even do like below ... -
我的图片根本没有显示(My image does not show at all)[2022-12-03]
路径 http://clicktravelnstay.com/img/photos/1344707033.png 返回404(未找到)。 您正在成功从数据库中提取图像名称,但实际的图像文件在您的服务器上不存在。 The path http://clicktravelnstay.com/img/photos/1344707033.png returns a 404 (not found). You're pulling the image name from the database successfully ... -
为什么我的图片没有出现?(Why does my image not appear?)[2023-11-09]
我猜这两个if语句中的一个正在评估为false: if image: if image.primary_image: url = images.get_serving_url(str(image.primary_image.key())) 如果您实际调用了get_serving_url,则可能会获得有效的服务URL或异常。 相反,url仍然有它的起始值,一个空字符串。 I would guess that one of these two if statem ...